Created
April 22, 2016 14:43
-
-
Save sketchpunk/e2e342124dc3db6bf5ec5aa5c66b1a30 to your computer and use it in GitHub Desktop.
Create a delegate function that keeps the reference of the parent object of the function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Delegate(obj,funcRef){ | |
var args = null; | |
if(arguments.length > 2){ args = []; for(var i=2; i < arguments.length; i++) args.push(arguments[i]); } | |
return function(){ | |
if(args == null) funcRef.apply(obj,arguments); | |
else{ | |
var params = args.slice(); //Need to make a copy of args, When just adding to args caused a problem with bubbling events. | |
for(var i=0; i < arguments.length; i++) params.push(arguments[i]); | |
funcRef.apply(obj,params); | |
}//if | |
}; | |
}//func |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment