Sul libro che sto leggendo si fa riferimento alla libreria extend() di Underscore.js ma io non riesco a farla funzionare. In console leggo:
Uncaught ReferenceError: extend is not defined
eppure nel file scrivo:
<script src="underscore-min.js"></script>
e nella cartella lo script c'è quindi proprio non capisco...
Per vedere il codice funzionare ho aggiunto davanti ad extend() i simboli $. però mi è scomodo ogni volta ricorrere a jQuery per testare i codici del testo. Qualcuno di voi ha una soluzione?
Ecco il codice "incriminato":
codice:var carPrototype = { gas: function gas(amount) { amount = amount || 10; this.mph += amount; return this; }, brake: function brake(amount) { amount = amount || 10; this.mph = ((this.mph - amount) < 0)? 0 : this.mph - amount; return this; }, color: 'pink', direction: 0, mph: 0 }, car = function car(options) { return extend(Object.create(carPrototype), options); }, myCar = car({ color: 'red' }); test('Flyweight factory with cloning', function () { ok(Object.getPrototypeOf(myCar).gas, 'Prototype methods are shared.' ); });


Rispondi quotando
