MoTTs_
Re:How Does React Tell a Class from a Function?
on Sunday December 09, 2018 @02:32AM (#18639834)
The issue we complain about in JavaScript is one like this:
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
}
};
Re:How Does React Tell a Class from a Function?
on Thursday December 06, 2018 @01:49AM (#18615961)
In C++ you have to use bind too.
Re:Ask HN: Resources for catching up on modern JavaScript for Python/C...
on Thursday April 12, 2018 @02:52AM (#16818578)
On the contrary, classes and inheritance in both Python and JavaScript behave basically the same. In Python, classes are objects (a building, not a blueprint), and inheritance is done by delegation.
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.
Re:‘This’ in JavaScript
on Thursday August 03, 2017 @11:45AM (#14920548)
> One of the last languages supporting prototype-based inheritance...
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...
Re:‘This’ in JavaScript
on Thursday August 03, 2017 @11:14AM (#14920279)
Beware referencing or learning from Eric Elliott.
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_...