Created
March 6, 2013 08:53
-
-
Save xenophy/5097732 to your computer and use it in GitHub Desktop.
Easy Delegate
This file contains hidden or 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(scope, fn, args) { | |
var me = this; | |
return function() { | |
fn.apply(scope, args || []); | |
}; | |
} | |
var df = Delegate(this, function(arg1, arg2, arg3) { | |
console.log("----"); | |
console.log(this); | |
console.log(arguments); | |
console.log("----"); | |
}, [1, 2, 3]); | |
var df2 = Delegate(this, function(arg1, arg2, arg3) { | |
console.log("----"); | |
console.log(this); | |
console.log(arguments); | |
console.log("----"); | |
}, ["A", "B", "C"]); | |
df(); | |
df2(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment