How Does React Tell a Class from a Function?
I have written maybe 200 lines of JavaScript in my life, and this article has strongly reinforced my desire to never have to write a single one more. The next time someone asks me what the problem with JavaScript is, I will send them this article. &quot;Scheme for the browser&quot; what a joke.<p>Some excerpts for those that didn&#x27;t have the strength to sit through the entire thing without pulling their hair out:<p>&gt; If you called Person(&#x27;Fred&#x27;) without new, this inside it would point to something global and useless (for example, window or undefined). So our code would crash or do something silly like setting window.name.<p>&gt; However, JavaScript also allows a function called with new to override the return value of new by returning some other object. Presumably, this was considered useful for patterns like pooling where we want to reuse instances:<p>&gt; However, new also completely ignores a function’s return value if it’s not an object. If you return a string or a number, it’s like there was no return at all.<p>&gt; And yet I still find it very confusing that a property called prototype does not give you a value’s prototype (for example, fred.prototype is undefined because fred is not a function). Personally, I think this is the biggest reason even experienced developers tend to misunderstand JavaScript prototypes.<p>&gt; However, some class implementations we wanted to target did not copy static properties (or set the non-standard __proto__), so the flag was getting lost<p>Edit: And I missed the best&#x2F;worst one yet: You can have MULTIPLE VERSIONS of the SAME DEPENDENCY running around in your codebase, interacting in ways that only god knows. In retrospect, this should have been obvious from the way javascript &quot;imports&quot; work, but, holy shit! If Satan himself had to design a language, he could not have done a better job. And I&#x27;m sure he would not have the stroke of genius required to make it the only programming language you can use if you want to target the most widely available platform for code in the world.<p>The next time I have to allow NoScript to let some js in, I will wonder how many goat sacrifices went into making the thing work.