The Prototype Concept
Much of the difference between JavaScript and languages like Java is that OOP in Java is based on a different type of class than in JavaScript. In traditional OOP, a class is a set and any object is an instance of that class or set. However, in JavaScript, the concept of class revolves around the concept of a prototype. Unlike the set concept of class that treats an instance of an object to be a member of the class, the prototype concept treats the named object with all of the properties that all members of the class have. For example, consider the class called Mall.
A Mall object has several characteristics expected in all malls. The following lists what just about any mall has:
A name (Bloomfield Mall)
Shops (butcher, ...
Get JavaScript Design now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.