I'm pretty much aware about prototype inheritance in js. But still scratching my head everytime, I try to understand difference between prototype and __proto__. Thankfully with ES6 classes and class inheritance constructs, we don't need to override prototype constructor and such a things anymore. Still wish, that somebody will explain it to me in plain english.
This post does try to explain it in plain English. See the explanation starting at the bolded sentence that starts "Confusingly,".
How Does React Tell a Class from a Function?
51–60 of 142 posts
Re: How Does React Tell a Class from a Function?
#52“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?
#53Re: How Does React Tell a Class from a Function?
#54Feels like yesterday to me. I still do my objects prototype style because classes feel too new and bleeding edge.
Re: How Does React Tell a Class from a Function?
#55Earlier quoted context omitted.
I don't understand how "React/Vue/Angular" is considered "an entirely new language." I use React primarily, so I'm going to speak from knowledge of that. It is very obviously a framework and it does one thing - handle your view. Depending on what you are doing, you may have very little react-specific code in your application. You have data fetching, caching, persistence, authentication, tons of things, not to mention…
While I agree with your point, your example of React literally adds a DSL that requires a pre-compilation step. It's not required[0], I get that, but it's still a new language. [0]: It may not be required, but it was created for a reason....
Personally I still use it, but I think it's fair to say that as much as JSX was created for a reason, it's made optional for a reason too.
Re: How Does React Tell a Class from a Function?
#56You get an error if you try to call an ES6 class as a function (without 'new'). So just try to do that inside a try-catch. If there is no error you know it is not a class and you have the result of the function already. If you do get an error and you know it is a function you know it must be a class.
I believe throwing and catching exceptions over and over as part of normal rendering is the sort of thing that would be disastrous for performance, certainly the sort of thing that the React authors would really want to avoid.
Re: How Does React Tell a Class from a Function?
#57Earlier quoted context omitted.
I don't mind a pre-compilation step as I'm already doing it in my projects and a lot of the community is as well. There are other templating systems you can use in React if you don't like JSX. I've seen one codebase use direct calls to ReactDOM.createElement and there is a new hotness (which I can't think of the name of now) that replaces JSX with template literals, something like: function NamePetList(props) { retur…
You're likely thinking of https://github.com/developit/htm .