5 ms·
“In the old days, JavaScript did not have classes” gave me a laugh. This was 3-4 years ago.
by ricardobeat 8y ago
“In the old days, JavaScript did not have classes” gave me a laugh. This was 3-4 years ago.
- welfare 8y agoHow I read it, "Old days" in my opinion refers to the 90's and early 00's, and not so much about the recent changes in the language.
- Vinnl 8y agoI guess he meant "the old days of React", i.e. in the first half or so of its lifespan.
- Grue3 8y agoMy reaction was "Wait, JavaScript has classes now???"
- Shorel 8y agoIf you have to use .bind(), then no, it doesn't.
- MoTTs_ 8y agoIn C++ you have to use bind too.
- Shorel 8y agoNo, not even close. You can use it if you want to, but it has never been popular in C++, and in 20 years I have never encountered a problem that could be solved by using it, so I have never used it. And in C++ bind is part of the functional programming paradigm, as it does currying, not much to do with classes. Bind in JavaScript makes your shoehorned collection of attributes actually behave like objects. We can see JavaScript's bind used everywhere.
- MoTTs_ 8y agoThe 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 } };