1. What is object-oriented?
JS in everything is the object! The bottom of all objects is like a hash array.
In a program, an object is used to describe a specific thing in reality, so-called object-oriented is the instantiation of a class.
One thing in the real world contains properties and functions:
Attribute: A variable that describes a thing's characteristics, a value
Functions: Things can be done by the operation
What is an object: encapsulates storage space for multiple data and methods
What is a custom object: encapsulates the storage space for the properties and functions of a thing in reality.
The properties of something in reality become an attribute variable in the object.
The function of something in reality becomes a method (function) in the object
How to create an object:
1. Object Direct Amount var obj={"Property name": value, XXX: ..., "method name":function() {... This . Property name ...} }
2. Use the New keyword var obj=New// to Create an empty object obj. property name = value; Obj. method name =function() {... this. Property name ...}
3. Create * Same structure * with constructor * repeating *object: constructor: A special function that describes a class of object Structures 2 steps:1. Defining Constructorsfunctionsumname (value1,.....) { This. property name =attribute parameter 1; //adds a property name to the object that is currently being created //value assigned to attribute parameter 1 ... This. Method name =function(){ ... This. Property name ...} } 2To create an object with a constructor:varobj=NewSumname (value1,...);
2. What are the characteristics of object-oriented?
Object-oriented three main features: encapsulation inheritance polymorphism
Encapsulation: A property and method that describes the same thing, defined in an object
Inheritance: Properties and methods in the parent object that can be used directly by the child object
Polymorphic: The same object, which renders different states in different situations
Note: Overloads--the same method name, incoming parameters differ, perform different actions
Overriding: A child object feels that a member of the parent object is not good to use and can define itself to overwrite the members of the parent object
Object-oriented in JavaScript