3 ms·
One single reason: refactoring. When the types of objects being passed to and returned by functions are known, you can modify the type of an object and know at
by d--b 8y ago
One single reason: refactoring.
When the types of objects being passed to and returned by functions are known, you can modify the type of an object and know at compile time that you forgot to update a usage of this type.
If objects have no known type, you may have some code that accesses properties that do not exist anymore.
- rodneon 8y agoThis is only a problem when you remove properties from an object. Ok, in this particular case, I buy your theory... but I'll ask again: is all the added cruft really worth this small safety? I mean, when you say "when the types of objects (...) are known"... isn't this the kind of stuff that tests are supposed to catch? You check to see if the object being passed into a function has all the properties it needs to have. Right? And if you need that kind of safety, couldn't you just enforce the use of constructors for "important" objects, and use instanceof to check for proper usage? All while using the constructs provided by JavaScript itself?