News for hackers. Stuff that matters.

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.
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...