Skip to content

Instantly share code, notes, and snippets.

@arieh
Last active February 11, 2016 05:53
Show Gist options
  • Save arieh/11af0b5d244ddae25d67 to your computer and use it in GitHub Desktop.
Save arieh/11af0b5d244ddae25d67 to your computer and use it in GitHub Desktop.
Bound mixin
function Bind(){
var i,fn;
/**
* holds the generated bound function collection
* @property bound
* @protected
* @type object
*/
this.bound = function(name){
if (!this.bound[name]){
try {
this.bound[name] = this[name].bind(this);
} catch (e) {
console.warn("Trying to bind undefined method " + name);
return;
}
}
return this.bound[name];
};
if (!this.bind) return;
};
//usage
class a{
constructor(){
Bind.call(this);
document.addEventListener('click', this.bound('onClick'));
}
onClick(){
console.log('click!');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment