Skip to content

Instantly share code, notes, and snippets.

@badsyntax
Last active August 29, 2015 13:56
Show Gist options
  • Save badsyntax/8803436 to your computer and use it in GitHub Desktop.
Save badsyntax/8803436 to your computer and use it in GitHub Desktop.
bad
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