Page 2 of 2
If this is the case how can you know what properties and methods an object has?
The simple answer to this is that you are the programmer so don't call a method or property unless you know or check that it exists.
You can either program in a relaxed style knowing that the objects that you are using conform to the requirements or you can program defensively and put checks in to make sure that methods and properties exist. This is just another example of the test for facilities rather than test for the browser that nearly all web programmers have adopted.
Put another way -
Notice also that you don't have to invent the idea of overriding methods, virtual methods or anything similar you can simply change a method when ever you need to. There are no function signatures - because there is no type - and there is no function overloading. Again when you call a function it is up to the function to make what it will of the parameters you pass it.
Of course we don't need generics either - as there is no type we don't need to invent a way to specify algorithms in a type free way.
Well this isn't quite correct.
The prototype mechanism is actually a way of allowing different instances to share the same code. It works by having a prototype object which defines the shared methods. When you create an instance, the instance has access to the shared methods as if they were defined locally - it really is that simple.
Prototypes are about shared code.
If you have had a lifetime of classical strongly typed static programming, you will probably be fuming that all of the rigorous coding conventions have just been dumped in favor of something that sounds so unstructured that they only thing that could come out of it are errors.
This isn't the case.
To be informed about new articles on I Programmer, subscribe to the RSS feed, follow us on Google+, Twitter or Facebook or sign up for our weekly newsletter.