News for hackers. Stuff that matters.
Re:How Does React Tell a Class from a Function? by ricardobeat on Monday December 03, 2018 @02:26AM (#18586966)
“In the old days, JavaScript did not have classes” gave me a laugh. This was 3-4 years ago.
Re:How Does React Tell a Class from a Function? by welfare on Monday December 03, 2018 @02:40AM (#18587025)
How 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.
Re:How Does React Tell a Class from a Function? by Vinnl on Monday December 03, 2018 @05:22AM (#18587688)
I guess he meant "the old days of React", i.e. in the first half or so of its lifespan.
Re:How Does React Tell a Class from a Function? by Grue3 on Monday December 03, 2018 @03:46PM (#18592794)
My reaction was "Wait, JavaScript has classes now???"
Re:How Does React Tell a Class from a Function? by Shorel on Monday December 03, 2018 @07:32PM (#18594679)
If you have to use .bind(), then no, it doesn't.
Re:How Does React Tell a Class from a Function? by MoTTs_ on Thursday December 06, 2018 @01:49AM (#18615961)
In C++ you have to use bind too.
Re:How Does React Tell a Class from a Function? by Shorel on Thursday December 06, 2018 @09:46AM (#18618404)
No, 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.

Re:How Does React Tell a Class from a Function? by MoTTs_ 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
            }
    };