Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on React v0.13 released. Parent comment
class Foo { constructor() { this.whatever = 4; }
bar() { this.whatever = 3; }
var foo = new Foo();
blah.onSomeEvent(foo.bar);
// When SomeEvent is triggered on blah, `this` will refer to blah, not foo.
console.log(blah.whatever); // 3 console.log(foo.whatever); // 4
// You have to: blah.onSomeEvent(foo.bar.bind(foo));
console.log(blah.whatever); // undefined console.log(foo.whatever); // 3
Which I know is just traditional JS, but it's a little unexpected because that's not how most OO languages operate.
There are no comments on this comment yet.
class Foo { constructor() { this.whatever = 4; }
}var foo = new Foo();
blah.onSomeEvent(foo.bar);
// When SomeEvent is triggered on blah, `this` will refer to blah, not foo.
console.log(blah.whatever); // 3 console.log(foo.whatever); // 4
// You have to: blah.onSomeEvent(foo.bar.bind(foo));
console.log(blah.whatever); // undefined console.log(foo.whatever); // 3
Which I know is just traditional JS, but it's a little unexpected because that's not how most OO languages operate.