Last active
August 29, 2015 13:56
-
-
Save badsyntax/8803436 to your computer and use it in GitHub Desktop.
bad
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
function FancyThing(options) { | |
this.message = 'hello'; | |
this.options = options; | |
} | |
FancyThing.prototype.doSomething = function() { | |
// yea, don't do this: | |
this.options.callback.call(this); | |
// this is better: | |
// this.options.callback(this) | |
}; | |
(new FancyThing({ | |
callback: function() { | |
console.log(this.message); // 'hello' | |
} | |
})).doSomething(); | |
(new FancyThing({ | |
callback: function() { | |
console.log(this.message); // undefined | |
}.bind({ other: 'object' }) | |
})).doSomething(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment