function to bind events to object methods given a string value list of event/handler pairs (e.g. on "click:clickMe;focus:focusMe")

This commit is contained in:
Scott Miles
2012-10-12 13:42:14 -07:00
parent 42195adfc5
commit 790391e025

View File

@@ -48,6 +48,18 @@ license that can be found in the LICENSE file.
}, this);
};
var bindEvents = function(inEvents) {
inEvents.forEach(function(e) {
// event name: handler name pairs
var pair = e.split(":");
var event = pair[0].trim();
var handler = pair[1].trim();
if (this[handler]) {
this.addEventListener(event, this[handler].bind(this));
}
}, this);
};
var deref = function(inNode) {
return inNode.baby || inNode;
};