What’s the difference between using _.extend({}, Backbone.Events) and _.clone(Backbone.Events) for an event aggregator? I have seen them both used for this purpose:
http://backbonejs.org/#Events
http://lostechies.com/derickbailey/2011/07/19/references-routing-and-the-event-aggregator-coordinating-views-in-backbone-js/
There is absolutely no difference. The definition of underscore’s
clonemethod is:So if the argument to
_.cloneis an object, the cloning is done via:Using the
_.extend({}, Backbone.Events)syntax makes sense, when you also want to define other properties on the new object. Becauseextendaccepts any amount of arguments, each of which will be extended into the first argument, it is common to define evented objects as follows: