Prototype Inheritance

Javascript and some other languages including NewtonScript and io are prototype-based. Prototypal languages differ from object oriented languages such as ruby and java as they do not use the class model where instances of classes are created from the class model which acts almost like a blueprint for the instances. In a prototypal language an object is created when defined. Methods are added to the prototype of the object. New objects are created by cloning the original object which inherits the methods of the original object.

Another difference is that with class based languages objects are defined at compile time so all the objects required for the program are created upfront. With prototype languages the objects are created at runtime so they are created as they are needed. These helps Javascript as it is run on browsers therefore it needs to be efficient with the resources on the client side. Especially since it was designed 10 years ago where this was a greater concern.

Lewis and Rebecca

Like what you read? Give Lewis Jones a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.