Better HN
topnewbestaskshowjobs
Log inSign up

MoTTs_

3 karma · joined Nov 9, 2016 (10y ago) · 5 submissions

Submissions

comment 7y ago · link · parent

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
            }
    };

comment 7y ago · link · parent

In C++ you have to use bind too.

comment 8y ago · link · parent

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.

comment 9y ago · link · parent

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

comment 9y ago · link · parent

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