Skip to content

Instantly share code, notes, and snippets.

@pthrasher
Created January 25, 2012 16:41
Show Gist options
  • Save pthrasher/1677154 to your computer and use it in GitHub Desktop.
Save pthrasher/1677154 to your computer and use it in GitHub Desktop.
how to fix js inheritance and class scope issues
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
function MyClass() {
this.my_method = __bind(this.my_method, this);
this.my_other_method = __bind(this.my_other_method, this);
}
MyClass.prototype.my_method = function(arg1) {
return arg1;
}
MyClass.prototype.my_other_method = function(arg1) {
return this.my_method(arg1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment