2 ms·
> Now onto bound methods: you are wrong in your code example; `instance.method()` does not require `method` to be a bound method; an unbound function is just fi
by dmitriid 8y ago
> Now onto bound methods: you are wrong in your code example; `instance.method()` does not require `method` to be a bound method; an unbound function is just fine.
Ah, true. I looked at the code, and was blind to it :)
> Understand this: React is not normal code. React was designed in a distinctly unusual way
There's nothing unusual about React.
> (they invented an rather substantial language extension to achieve it!)
That "extension" is nothing but function calls [1] [2]
Quote: "Each JSX element is just syntactic sugar for calling React.createElement(component, props, ...children). So, anything you can do with JSX can also be done with just plain JavaScript."
> This is not JavaScript’s fault
It is entirely Javascript's fault. That is, it's the fault of its haphazard development with reckless disregard to any long-term planning.
Classes are deliberately designed to look and behave, for the most part, like classes in C++-like languages. So they hid the whole prototype chain away behind the class keyword... But it's still there, and you have to be always consciously aware of it.
As for the rest of your example, and how "you would rarely need to bind methods", well even the class fields proposal binds methods in its examples. So much for "rare" [3] And with quite a few people using WebComponents which are also class-based, well... Just a literally the first example I found: [4]
And of course class fields will behave like class fields in C++-like languages will behave. Unlike methods. Because reasons.
And of course, the "solution" to that is to throw in another half-baked solution in the form of a decorator. Which will take another several years to go through the standardization stage. ¯\_(ツ)_/¯
[1] https://reactjs.org/docs/jsx-in-depth.html https://reactjs.org/docs/jsx-in-depth.html
[2] https://reactjs.org/docs/react-without-jsx.html https://reactjs.org/docs/react-without-jsx.html
[3] https://github.com/tc39/proposal-class-fields https://github.com/tc39/proposal-class-fields
[4] https://github.com/elmsln/lrnwebcomponents/blob/master/elements/a11y-collapse/src/a11y-collapse.js#L213 https://github.com/elmsln/lrnwebcomponents/blob/master/eleme...