XObject.js
authoralan <alan@alanfast.akbkhome.com>
Thu, 15 Apr 2010 10:43:26 +0000 (18:43 +0800)
committeralan <alan@alanfast.akbkhome.com>
Thu, 15 Apr 2010 10:43:26 +0000 (18:43 +0800)
XObject.js

index 31048ba..793c9f6 100644 (file)
@@ -323,4 +323,34 @@ XObject.extend(XObject,
         }
         return ret;
     }
+    
+     },
+         
+    /**
+     * @function createDelegate
+     * creates a delage metdhod
+     * @param {Function} method to wrap
+     * @param {Object} scope 
+     * @param {Array} args to add
+     * @param {Boolean|Number} append arguments or replace after N arguments.
+     * @return {Array} returns list of kyes
+     * @member Object keys
+     */
+
+    createDelegate : function(method, obj, args, appendArgs){
+        
+        return function() {
+            var callArgs = args || arguments;
+            if(appendArgs === true){
+                callArgs = Array.prototype.slice.call(arguments, 0);
+                callArgs = callArgs.concat(args);
+            }else if(typeof appendArgs == "number"){
+                callArgs = Array.prototype.slice.call(arguments, 0); // copy arguments first
+                    var applyArgs = [appendArgs, 0].concat(args); // create method call params
+                    Array.prototype.splice.apply(callArgs, applyArgs); // splice them in
+                }
+                return method.apply(obj || window, callArgs);
+            };
+    },
+    
 });
\ No newline at end of file