Exploring whether javascript is an object-oriented language _ javascript skills-js tutorial

Source: Internet
Author: User
This article mainly introduces whether javascript is an object-oriented language. For more information, see <G id = "1"> Object Management </G>. Objects can contain other objects. He has no class (before javascript2.0 is actually implemented), but it has a constructor that can do what the class can do, including containers and roles that play variables and methods. It does not have class-based inheritance, but it has prototype-based inheritance. The two methods to create an object system are inherited and aggregated. JavaScript.

2. Some comments say that javascript is not really object-oriented because it cannot provide information hiding. That is, the object cannot have private variables and private methods: all members are public. However, some people subsequently demonstrated that javaScript objects can have private variables and private methods. In addition, it was criticized that javascript cannot provide inheritance, but some people later proved that javascript not only supports traditional inheritance, but also applies other code reuse modes.

3. javascript is an object-based language, which is a correct and slightly conservative judgment. javascript is not object-oriented, which in my opinion is a false perception, in fact, there are ample reasons to prove that javaScript is an object-oriented language, but javaScript is different from the traditional class-based object-oriented language, this uniqueness is called prototype-Based Object-Oriented.

-----------------------------------------

Because js is a weak type language, unlike c ++ and C! He does not support function method overloading. You have previously written a method. Then, write another method with the same name. By default, he will overwrite the previous method! This is the same as that in PHP!

It does not support function overloading in languages such as C #. Different methods are called based on different parameters and return values!

Javascript is not object-oriented. It is not completely object-oriented. It can also be written as classes, methods, and attributes, but it is slightly different from other languages! For example
Var cls = {
My: {a: 0 },
Init: function ()
{
Alert (this. my. );
}
};
Window. onload = function ()
{
Cls. init ();
}

Call cls. init ();

This is his class, but it lacks a lot of object-oriented features. It is very clear above! So he is not completely object-oriented.

Object-oriented is just a way of thinking and a way of thinking!

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.