Last active
August 29, 2015 14:13
-
-
Save mtford90/6a44740064c5c8135c68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
commented
Jan 21, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment