Prototype chain
Is a relationship, the relationship between the object and the prototype object instance, by the relationship between the prototype ( proto ) to contact the
this point
Constructor this is an example of an object
prototype object of this method is also an object instance
Prototype point
Prototype points may be changed
instance of an object prototype __proto__ pointed object constructor is the prototype of the object resides
prototype object constructor (the prototype) If the change point, the prototype (object instance proto ) is also changed to point
The prototype is achieved by pointing the prototype chain
DIRECTION
__proto__ instance object points to a constructor prototype, prototype constructor __proto__ points to the object prototype, the prototype object of the null point __proto__
function Student() {
}
Student.prototype.sz = function(){
console.log("student");
}
var student = new Student();
console.log(student.__proto__ == Student.prototype); //true
console.log(student.__proto__ .__proto__ == Student.prototype.__proto__); //true
console.log(Student.prototype.__proto__ == Object.prototype ); //true
console.log(Object.prototype.__proto__); //null
Examples of objects and attributes duplicate names in the prototype object
Examples of prototype objects and object attributes have this preference attribute instance object
to change the value of the object instance
function Person(age){
this.age = age;
}
Person.prototype.age = 30;
var ps = new Person(10);
A complete prototype chain
var divObj=document.getElementById("dv");
console.dir(divObj);
//divObj.__ proto __----> HTMLDivElement.prototype of __proto __-> HTMLElement.prototype of __proto __----> Element.prototype of __proto __----> Node.prototype of __proto __--- -> EventTarget.prototype of __proto __----> Object.prototype no __proto__, therefore, Object.prototype in __proto__ is null
Object-oriented language features
Object-oriented programming languages have a class (class) concept, but not js object-oriented languages, but based on object-oriented language, so there is no js class. Js but can simulate the idea of object-oriented programming, js class concept can be simulated by the constructor
-
Packaging Packaging ----
-
---- inheritance relationship between class and class, js no class. Simulations in the constructor, achieved by the prototype inheritance
-
---- polymorphic object has a different object, or the same behavior for different objects, different results, to how states will inherit the existing, js can simulate multi-state, but will not using this method, because the effect is minimal and take up a lot of resources, so we will not be simulated