Javascript is a prototype-based language ), c ++, Object Pascal, C #, and Java are class-based languages. Another important feature is that JavaScript is a dynamic language, c ++ is a static language (C # also introduces some dynamic features in version 4.0 ).
Class-based language (Java) |
Prototype-based language (JavaScript) |
Classes and instances are independent entity concepts. |
All objects are instances. |
Define a class using the Definition Statement of the class. Use the constructor to instantiate a class. |
Use constructors to define and create a series of objects |
Use the new operator to create an object |
Same |
Use the Definition Statement of the class to define a subclass of an existing class, and then create the hierarchical relationship of the object. |
Create an object using the constructor class, assign a prototype object and associate it with an existing construct an object hierarchy by assigning an object as the prototype associated with a constructor function. |
Inherit properties by following the class chain. Inherit attributes through classes |
Inherit properties by following the prototype chain. Inherit attributes through prototype |
Class Definition specifies all properties of all instances of a class. Cannot add properties dynamically at run time. Class defines all attributes of the instance and cannot be dynamically added at runtime. |
Constructor function or prototype specifies an initial set of properties. Can add or remove properties dynamically to individual objects or to the entire set of objects. The constructor or prototype defines the original set of attributes. You can dynamically add or delete attributes at runtime. |
Refer:
Http://en.wikipedia.org/wiki/Prototype_pattern
Http://en.wikipedia.org/wiki/Prototype-based
Http://en.wikipedia.org/wiki/JavaScript
Class-based vs. Prototype-based ages