3 karma · joined Nov 9, 2016 (10y ago) · 5 submissions
comment 7y ago · link · parent
class C {
handleEvent() {}
someMethod() {
onEvent(this.handleEvent); // bad; "this" lost
onEvent(this.handleEvent.bind(this); // ok
}
}
C++ requires the same thing. The bad case will even generate an error at compile time. class C {
public:
void handle_event() {}
void some_method() {
on_event(&C::handle_event); // bad; error
on_event(std::bind(&C::handle_event, this)); // ok
}
};comment 8y ago · link · parent
https://i.imgur.com/p9Kw815.png
If you've used Python classes and inheritance all this time and never felt confused, then people can also use JavaScript's classes and inheritance and never feel confused.
comment 9y ago · link · parent
Actually, all this time, both Python and Ruby use what we would call prototype-based inheritance.
https://www.reddit.com/r/node/comments/6oqiyn/is_es6_complet...
https://www.reddit.com/r/learnjavascript/comments/6c6use/how...
comment 9y ago · link · parent
https://www.reddit.com/r/javascript/comments/6q2lk0/why_comp...
https://www.reddit.com/r/javascript/comments/5c5lkq/what_eri...
https://www.reddit.com/r/javascript/comments/3x91ac/why_not_...