The difference between JS prototype object and Java class

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.