Reputation:
Searching backbone I see it is used 12 times and always attached to this
inside of Backbone.Events.
Is it simply a property of Backbone.Events? If so why does it have the underscore prefix?
What is it used for?
on: function(name, callback, context) {
if (!(eventsApi(this, 'on', name, [callback, context]) && callback)) return this;
this._events || (this._events = {});
var list = this._events[name] || (this._events[name] = []);
list.push({callback: callback, context: context, ctx: context || this});
return this;
},
Upvotes: 1
Views: 2039
Reputation: 5060
The underscore is meant to indicate that it should be treated as a private property. _events
is a map of event callbacks used by Backbone.Events.
Any property or method added to a javascript object is public. The underscore is a widely used convention to show that the property/method is not to be used outside of the object.
Here is a classic link that explains it a bit: http://javascript.crockford.com/private.html
Upvotes: 4