From today on to write their own learning things, a little excited. (Just give mom massage foot, finger a bit bad to make) good, nonsense not to say, this is learning is JS object-oriented knowledge.
Object-oriented : is to use the idea of the object to write code, and we usually write JS is the process of writing. What is an object ? In fact, in the native JS there are many system objects, such as Date,array,json (object) and so on.
Object-oriented Programming (OOP) features: 1. Abstract: Seize the core question; 2. Encapsulation: Methods can only be accessed through objects; 3. Inheritance: A new object is inherited from an existing object; 4. Polymorphism: Different forms of multiple objects.
The composition of the object: Property + method. Next, create the first object.
function Aaa () { this. Attribute // property is written }varnew function() {}// method is written
The above should be noted: 1. Capitalize the first letter. 2. Extract with the new keyword. 3. When using new to invoke a function AAA, this time the function is a pointer to the creation of this object A, and the return value of this function is the object A.
Constructor: Is the function Aaa () {...} above.
Prototype-prototype
Definition: Overriding an object method to allow the same method to exist in memory (improve performance).
Principle: The same properties and methods can be written to load on the prototype. For example: Array.prototype.sum = function () {}
Summarize the object-oriented notation: constructor ~ property; prototype ~ method.
JavaScript Object-oriented one