javascript - What does "this._events || (this._events = {});" mean? -


I have started learning backbone.js. Currently my javascript skills are not very good. I have started checking the backbone.js file and I've got a strange line code whose purpose I can not understand. Code sample (if you need more context, manually download for developers and see line 80):

  var Events = Backbone.Events = {// callback to an event callback 'Tie in function. The "all" passes will have callback / bind to close all events. On: Function (Name, Callback, Context) {If (! Event API (this, 'on', name, [callback, reference]) .backback); This._events || (This._events = {}); Var events = this._events [name] || (This._events [name] = []); Events.push ({callback: callback, context: context, CTX: context || this}); Back it; },   

line this._events || (This._events = {}); mean? For me, _events looks like an internal variable, but used for (this._events = {}) assignment, or it's a or < / strong> is a comparison? Or = Is there a completely different process in this context?

This is a trick that Javascript uses "false" evaluation: this is the same:

  if (this._events) {// nothing is, this._ events are already defined} other {this._events = {}; }   

goes to the same line var events = this._events [name] || (This._events [name] = []); can be translated into

  var events; If (this._ events [name]) {events = this._events [name]; } Other {these._events [name] = []; Events = this._events [name]; }    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -