Explore JavaScript as an object-oriented language _javascript technique

Source: Internet
Author: User

1 It possesses objects that can contain data and methods of processing data. Objects can contain other objects. He has no class (before javascript2.0 really implemented), but it has constructors that can do what the class can do, including containers and roles that act as variables and methods. He does not have a class based inheritance, but it has a prototype based inheritance. Two ways to establish an object system are through inheritance and through aggregation. There are two JavaScript.

2 Some evaluations say that JavaScript is not really object-oriented because it does not provide the hidden information. That is, an object cannot have a private variable and a private method: all members are public. But then someone proved that JavaScript objects can have private variables and private methods. There is also criticism that JavaScript does not provide inheritance, but it was later proved that JavaScript not only supports traditional inheritance but also applies other code reuse patterns.

3 said that JavaScript is an object-based language, is a correct and slightly conservative judgment, and that JavaScript is not object-oriented, in my view is wrong cognition, in fact there is ample reason to prove that JavaScript is an object-oriented language, It's just that JavaScript has a different place than a traditional class-oriented object, which we call a prototype based object-oriented.

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

Because JS is a weakly typed language. Unlike c++,c#, this type of language! He does not support function method overloading. You write a method before. He will override the previous method by default! This situation is the same as in PHP!

He doesn't look like C #. Languages support function overloading. Depending on the parameters, the return value calls a different method!

About JS is not object oriented. He is not entirely object-oriented, he can also write classes, methods, attributes. But it's a little different than any other language!
var cls={
my:{a:0},
Init:function ()
{
alert (THIS.MY.A);
}
};
Window.onload=function ()
{
Cls.init ();
}

Call Cls.init ();

This is his class, but a lot of object-oriented features are missing. The upstairs is very clear! So he's not completely object-oriented.

Object-oriented is just a way of thinking to solve the problem!

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.