Object-oriented and process-oriented
Before using object-oriented thinking structured code, all written in a bunch of js code, that is process-oriented (Code piled up together, distinguished by annotation)
Object-oriented as will be appreciated, the package is highly procedural code, aims to improve the maintainability and efficiency of the code development.
Understand what the object: a thing has certain characteristics or a certain method (which is the property, its behavior is the way)
Three ways to create an object of ways:
1. literal way
2. Call the constructor of the system
3. customize the way the constructor
// Create an object literal embodiment the let PER1 = { name: 'white' , Age: 10 , say: function () { return 'Hello' } } // constructor call to create the object system the let Per2 = new new Object () per2.name = 'Huang' per2.age =. 8 per2.eat = function () { return 'EAT something' } // custom constructor creates the object function the Per3 (name, Age) { the this .name = name the this . = Age Age the this .play = function () { return "Play gemes' } } the let Per3 = new new the Per3 ( 'small yellow', 10 ) // factory pattern to create the object function creatObject (name, Age) { the let obj = new new Object () obj .name = name obj.age = Age obj.say = function () { the console.log ( 'Hello' ) } return obj } the let per4 = creatObject ( 'white', 10)
Object-oriented programming --Object Oriented Programming - OOP
js can simulate object-oriented
object-oriented properties: encapsulation, inheritance, polymorphism, abstract
Package: code reuse
concept class, refers to the relationship between class and class, js no notion of class constructors - the key concepts: Inheritance , based on the prototype can be inherited, the concept of simulation by the constructor of the class.
Polymorphism: An object behave differently, or the same behavior for different objects, produce different results
Object-oriented design is:
-
Abstract Class
-
Creating Instance according to Class
-
Command Instance was the result of
to sum up:
That is, according to requirements, analysis objects, found objects what characteristics and behavior, by creating an object (object-oriented constructor to create the object ), call the object properties and methods to achieve demand.