I’ve been exploring backbone js recently and found the use of Model and others is like this:
Backbone.Model.extend({ /* bla bla */ });
And it’s using underscore js’s extend function to do that
I saw extend just used for adding properties to an object
So, what’s the big deal if I use myObj.extend({myProp: myPropValue});
instead of myObj.myProp = myPropValue;
UPDATE:
I found this as addition. I think it’s cool
They both achieve the same result. However the
extendmethod is more flexible because you can add multiple properties in a single call.But
extendis a function that originated in jQuery and is not native to Javascript, and has been implemented in underscore.js so the native method ofmyObj.myProp = myPropValue;will be more efficient, and is available without the aid of jQuery or underscore.js.The difference in performance though is likely to be so negligible that using
extendshouldn’t be something to worry about.