"Javascript is not an object-oriented language"
No one opposed this sentence.
So what is object-oriented?
To put it simply, "Object-Oriented is to abstract things in reality". "The word" Object-Oriented "may make it more appropriate ".
Definition 1: The object-oriented method is a method to construct, test, and reconstruct software by using the concepts of objects, classes, encapsulation, inheritance, polymorphism, and messages.
Definition 2: The object-oriented method is based on the theory of cognition. It uses objects to understand and analyze the problem space, and designs and develops a software system (solution space) composed of objects. Because the problem space and the solution space are composed of objects, this can eliminate the problems caused by the inconsistency between the problem space and the solution space structure. In short, object-oriented is the process of thing-oriented analysis, and the process of understanding the objective world.
Is there an Object Concept in JavaScript?
Yes. Check the script to make it correct:
VaR OBJ = New Object ();
OBJ. Width = 12 ;
Alert (obj. width );
However, JavaScript does not have the concept of inheritance, and thus does not have the concept of polymorphism. In fact, each JavaScript Object is an instance of the same base class.
Many people do not distinguish between "Object-Oriented" and "Object-based. The three characteristics of object-oriented (encapsulation, inheritance, and polymorphism) are indispensable. objects are usually used based on objects, but existing Object Templates cannot be used to generate new object types, then, a new object is generated. That is to say, "Object-based" does not have the inheritance feature, and "polymorphism" is a subclass object instance of the parent class, without the concept of inheritance, we cannot talk about "polymorphism". Without the inheritance and polymorphism features, JavaScript is just an object-based language.
Note:
Today, I am reading jquery. js. We can see something related to prototype. js and talk about JavaScript inheritance. Maybe I was wrong at the beginning and hoped that I would not mislead others. The content is as follows:
Class inheritance is actually supported by JavaScript, but prototype provides another method.
Based on the implementation supported by javascript:
VaR Student = Class. Create ();
Student. Prototype = New Person ();
In this way, student is inherited to person.
This can be achieved when prototype is used:
VaR Student = Class. Create ();
Object. Extend (student. prototype, person. Prototype );
You can use this method to add a subclass.
Student. Prototype. Study = Function () {} ;
Or
Object. Extend (student. prototype, {
Study:Function(){}
} );