Explorar el Código

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

Sebastián Katzer hace 7 años
padre
commit
7622df53cd
Se han modificado 1 ficheros con 6 adiciones y 1 borrados
  1. 6 1
      www/local-notification.js

+ 6 - 1
www/local-notification.js

@@ -439,8 +439,9 @@ exports.setDefaults = function (newDefaults) {
  * @return [ Void ]
  */
 exports.on = function (event, callback, scope) {
+    var type = typeof callback;
 
-    if (typeof callback !== "function")
+    if (type !== 'function' && type !== 'string')
         return;
 
     if (!this._listener[event]) {
@@ -499,6 +500,10 @@ exports.fireEvent = function (event) {
         var fn    = listener[i][0],
             scope = listener[i][1];
 
+        if (typeof fn !== 'function') {
+            fn = scope[fn];
+        }
+
         fn.apply(scope, args);
     }
 };