Skip to content

Instantly share code, notes, and snippets.

@RStankov
Created September 11, 2009 08:06
Show Gist options
  • Save RStankov/185157 to your computer and use it in GitHub Desktop.
Save RStankov/185157 to your computer and use it in GitHub Desktop.
//
// ------------------------
// Class.Mixin.Delegator
// ------------------------
//
// Usage:
// adding:
// - MyClass.addMethods(Class.Mixin);
// usage (in MyClass):
// this.delegate('element', 'observe', 'setPosition');
//
//= require<prototype>
Class.Mixin = {};
Class.Mixin.Delegator = (function(){
function delege(to){
var methods = Array.slice(arguments, 1), method;
for(var i=0; i<methods.length; i++){
this[method] = this[to][method].bind(this[to]);
}
}
return {delegate: delegate};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment