I know backbone is somewhat depending on underscore and jquery. Is there difference between the two lines below?
app.notifications = _.extend({}, Backbone.Events);
AND
app.notifications = Backbone.Events.extend({});
If they are NOT the same, how different?
js extend view is a method under the view class that is used to extend the backbone. js view class in order to create a custom view class. For implementation, first of all, we need to create a custom view class and override the render function if required, also we can specify our own declarative events.
Backbone. js is a model view controller (MVC) Web application framework that provides structure to JavaScript-heavy applications. This is done by supplying models with custom events and key-value binding, views using declarative event handling and collections with a rich application programming interface (API).
You can use the Backbone. Model without jQuery, but Backbone.
js Event once() The event once method is just like event on method but it causes the bound callback to only fire once before being removed.
Backbone.Events.extend does not exist, so I will refer to Backbone.Model instead.
_.extend(target, mixin1, mixin2)
is going to copy properties into the target object
Backbone.Model.extend is going to subclass
Backbone.Model basically make a constructor (function) whose prototype has your provided properties. This will allow you to make instances of your new class
var Person = Backbone.Model.extend({name: 'yourName'});
var me = new Person();
alert(me.name);
while _.extend
would fail
var Person = _.extend({name: 'yourName'}, Backbone.Model);
var me = new Person(); //error b/c Person is a regular object
alert(me.name);
In short Backbone.Model.extend creates a new constructor (function), while _.extend modifies an existing object;
var modified = {};
alert(modified === _.extend(modified, Backbone.Model)); //true
alert(modified === Backbone.Model.extend(modified)); //false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With