Skip to content

Instantly share code, notes, and snippets.

@xenophy
Created March 6, 2013 08:53
Show Gist options
  • Save xenophy/5097732 to your computer and use it in GitHub Desktop.
Save xenophy/5097732 to your computer and use it in GitHub Desktop.
Easy Delegate
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