Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Created June 22, 2017 18:27
Show Gist options
  • Save ajcrites/c19b64df274acb0891c93aac0c062488 to your computer and use it in GitHub Desktop.
Save ajcrites/c19b64df274acb0891c93aac0c062488 to your computer and use it in GitHub Desktop.
const Foo = function () {}
Foo.prototype.bar = "bar",
Foo.prototype.arrow = () => {
console.log(this.bar);
};
Foo.prototype.fn = function () {
console.log(this.bar);
};
Foo.prototype.handyArrow = function () {
process.nextTick(() => console.log(this.bar));
};
Foo.prototype.badFn = function () {
process.nextTick(function () {
console.log(this ? this.bar : undefined);
});
};
const f = new Foo;
f.arrow();
f.fn();
f.handyArrow();
f.badFn();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment