3 ms·
Interesting point, but I'm not able to judge the trutfulness. So the JVM has a runtime-enforced nominal type system (and object model) with classes. But JS, t
by moritzwarhier 1y ago
Interesting point, but I'm not able to judge the trutfulness.
So the JVM has a runtime-enforced nominal type system (and object model) with classes.
But JS, to my knowledge, only has primitive types enforced at runtime, and no nomimal class system, unless you basically implement it yourself?
Uh, edit: maybe I get you now, it does have that in a way. But prototype identity and "instanceof" are rarely used in practise.
Maybe I'm missing your point here. Answering at late local time.
It would be so great to have a nominal type system in the browser though.
So many JS librarlies have their own version of it, and it causes insufferable headaches when combined with TypeScript.
Like, they use complicated hacks to make sure that their library objects are not structurall/duck typed.
- twoodfin 1y agoclasses != objects Yes, the typing and semantic models are wildly different. The point is that they’re primitive in a way that the other widespread alternative, C++, did not inherit from its Cfront heritage.
- moritzwarhier 1y ago> classes != objects that's what I was aiming at, maybe poorly. There's tons of libraries that use some kind of runtime-observable instance property as a tag, to mimic nominal typing in JS. The same thing is also possible using prototype identity, if you either use the class keyword syntax sugar introduced with ES5 (?), or if you manually do OOP using prototypes. But the latter is very uncommon. It seems to be more common to add a property like $_$_$____superlib__$-inst_WALRUS and use that as a tag.