When I was learning JavaScript's prototype object, I always did not consciously take the Java class thought to do the comparison, the time is long, I gradually realized that the two have the huge difference.
First, the class is not directly run as a method, its simplest way is to call its static method, and the prototype object itself is a method body, it can run directly. In the process of constructing the object, JS can play two roles, one can use the prototype object as a method, before touching JS, are used in this form, that is, everything is the method body, like C; the other is to imitate object-oriented features, define properties for the prototype object, use the constructor, The pointer to the object constructed by the constructor refers to the properties of the prototype object through the prototype chain, thus implementing the object-oriented programming form. In fact, do an interesting experiment, define a prototype object, define some properties for it, and define some of the code that can be executed automatically, such as:
<! DOCTYPE html>And this, allow the phenomenon of mixed in Java class is absolutely not allowed, this can also reflect why JS is based on objects, and not known as the absolute norm of the completely object-oriented, rather than JS "imitate" the use of object-oriented thinking, I am more inclined to say that it is borrowed object-oriented thinking. If a new idea of good programming is created, JS can imitate it with its flexibility, and those strongly-typed programming languages are likely to only ...
The difference between JS prototype object and Java class