Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Last active August 29, 2015 14:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ryanflorence/11243082 to your computer and use it in GitHub Desktop.
Save ryanflorence/11243082 to your computer and use it in GitHub Desktop.
function delegate (child) {
// make it happen
}
// usage
var obj = {
math: {
x: 2,
add: function (y) {
return this.x + y;
},
multiply: function (y) {
return this.x * y;
}
},
add: delegate('math'),
multiply: delegate('math')
};
// test cases
console.assert( obj.add(1) === 3 );
console.assert( obj.multiply(3) === 6 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment