javascript - Understanding Cranium.js code -


i reading cranium.js (https://gist.github.com/addyosmani/3769967) code addy osmani , not understand 2 lines of javascript do. entire code following:

// mix in object in order provide custom events. var events = cranium.events = {         channels: {},         eventnumber: 0,         trigger: function (events, data) {             (var topic in cranium.events.channels){                 if (cranium.events.channels.hasownproperty(topic)) {                     if (topic.split("-")[0] == events){                         cranium.events.channels[topic](data) !== false || delete cranium.events.channels[topic];                     }                 }             }         },         on: function (events, callback) {             cranium.events.channels[events + --cranium.events.eventnumber] = callback;         },         off: function(topic) {             delete cranium.events.channels[topic];         }             }; 

the first line don't understand is:

if (topic.split("-")[0] == events){                             cranium.events.channels[topic](data) !== false || delete cranium.events.channels[topic];                         } 

that is: understand if, don't happening inside curly braces. seems me (but wrong) if left expression true nothing happens, if not deletes cranium.events.channels[topic].

the second line don't understand is:

cranium.events.channels[events + --cranium.events.eventnumber] = callback; 

i don't understand double minus sign.

any comment appreciated.

if (topic.split("-")[0] == events){     cranium.events.channels[topic](data) !== false || delete cranium.events.channels[topic]; } 

is same

if (topic.split("-")[0] == events){     if ( cranium.events.channels[topic](data) === false ) {         delete cranium.events.channels[topic];     } } 

and in cranium.events.channels[events + --cranium.events.eventnumber] = callback; -- subtracting 1 cranium.events.eventnumber before applying it. so, if 3 before, 2 added events.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -