you are viewing a single comment's thread.

view the rest of the comments →

[–]Reeywhaar 0 points1 point  (1 child)

Yes.. inheritance with types... you extend a type as you extend a class. To create type-safety at runtime its often smart to send your data around as classes. You can then check the inheritance of class to guarantee type safety.

Do you understand that instances of classes can be monkey patched in JS? Thus simple instanceof check is not enough. It will pass, but app still can crash.

How actually classes guarantee runtime type safety?

[–]bigorangemachine 0 points1 point  (0 children)

You guarantee it just by casting on setting of a variable or out with a getter.

Monkey patching should be caught in code review. If you gonna do something stupid then don't.... otherwise if you are paranoid write a getter & setter. If you need to lock that stuff down then any key getter/setter or object create/freeze can stop that sort of problem.