|
|
|
|
|
by sergeykish
2075 days ago
|
|
I occasionally write JavaScript since 2007, experiment a lot last 5 years, red through ES5 specification several times. I've worked as C++, PHP, Python, Ruby developer. Experimented with a few languages. "JS" instead of "TypeScript" brings confusion. TS solves some issues and I've mentioned it, still typeof null
//"object"
Template literals interpolation helps but if string (not literal string) slips by it is a mess 1 - "2"
//-1
1 + "2"
//"12"
Check out another comment [1], Object, Function, etc defined as constructor. It is not solved by "class", it is still a function with a bit of sugar: class Foo {}
Foo instanceof Function
//true
Globals with a few exceptions defined as constructors, DOM elements defined as constructors, inheritance defined as constructors class Bar extends Foo {}
You can internalize how it works and there are some good explanations [2] but design is error prone and terrible.[1] https://news.ycombinator.com/item?id=24815922 [2] https://yehudakatz.com/2011/08/12/understanding-prototypes-i... |
|
`typeof null === "object"` is a mistake (like with most of the big ones, blame MS for refusing to ratify any spec that actually fixed them).
If you're having issues accidentally replacing `+` with `-` then you have bigger issues (eg, not unit testing). I'd also note that almost all the other languages you list allow you to overload operators which means they could also silently fail as well. In any case, garbage in, garbage out.
Foo being an instance of function is MUCH more honest than it being an instance of a class because the constructor in all languages is actually a function. This is even more true because you are looking at the primitive rather than the function object which contains the primitive.