Skip to content

Instantly share code, notes, and snippets.

@mtford90
Last active August 29, 2015 14:13
Show Gist options
  • Save mtford90/6a44740064c5c8135c68 to your computer and use it in GitHub Desktop.
Save mtford90/6a44740064c5c8135c68 to your computer and use it in GitHub Desktop.
var myAPI = {
doSomeShit: function (cb) {
// Need to preserve the binding of cb,
// but you can't do cb.this - there's no way to find out what it's bound to
cb.call(cb.this, 'arg1', 'arg2')
}
};
function MyClass() {
this.shitIsDone = false;
}
MyClass.prototype.foo = function () {
myAPI.doSomeShit(function () {
this.shitIsDone = true;
}.bind(this))
}
var myInstance = new MyClass();
myInstance.foo();
@vitosamson
Copy link

doSomeShit: function(cb) {
  cb.prototype.returnThis = function() { return this; };

  cb.call(cb.returnThis(), 'arg1', 'arg2');
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment