Object-oriented (OOP): is a development process, with an object-oriented programming thinking to develop.
In JS, we generally use process-oriented development.
Object-oriented Features: abstraction, encapsulation, inheritance, polymorphism
First look at how custom objects are written: Customize a person's object, the person's name, age, or talk. In the following, the name is the attribute of this person, speaking is the person's behavior, can also be called methods. This can also be understood as a simple object-oriented programming. Where the object comes from, such as Var arr=new array (); This is an array of objects, from the JS of a default system method class.
For example: Define a person's class, each person is one of the objects of this person's class, and people have common properties and methods, such as name, can talk and so on. This public property and public method are also called
Exposes properties and exposes methods.
<script type= "Text/javascript" >
var people={
Name: ' WT ',
Age:22,
Calls:function () {
Alert (' OK ');
}
};
alert (people.name);
People.calls ();//ok
</script>
To customize a class in JS is to use function to do keywords; to customize a human. Set its public properties (Name,age,) and public methods (talk)
such as function person (name,age) {//This also called a constructor is also a class
This.name=name;//this is an implicit pointer to an instantiated object where name is a property
This.age=age;
This.talk=function () {//This is a public method
alert (this.name);
}
}
Instantiate an object called Xiaoming
var xiaoming=new person (' xiaoming ', ' 25 ');
Call Xiaoming's age and name and talk about this behavior in the following way
alert (xiaoming.name);//xiaoming
alert (xiaoming.age);//25
Xiaoming.talk ();//xiaoming
Above is a simple example of object-oriented programming, and how to customize a class and set the invocation of properties and methods and properties and methods.
/*****************/