Commit 7622df53 by Sebastián Katzer

Allow on() to accept a string wich refers to a function of the scope at runtime

parent 7f869091
...@@ -439,8 +439,9 @@ exports.setDefaults = function (newDefaults) { ...@@ -439,8 +439,9 @@ exports.setDefaults = function (newDefaults) {
* @return [ Void ] * @return [ Void ]
*/ */
exports.on = function (event, callback, scope) { exports.on = function (event, callback, scope) {
var type = typeof callback;
if (typeof callback !== "function") if (type !== 'function' && type !== 'string')
return; return;
if (!this._listener[event]) { if (!this._listener[event]) {
...@@ -499,6 +500,10 @@ exports.fireEvent = function (event) { ...@@ -499,6 +500,10 @@ exports.fireEvent = function (event) {
var fn = listener[i][0], var fn = listener[i][0],
scope = listener[i][1]; scope = listener[i][1];
if (typeof fn !== 'function') {
fn = scope[fn];
}
fn.apply(scope, args); fn.apply(scope, args);
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment