I. Object: Normal Object Function object
Two. Constructor features: 1. A new instantiation is required, and the This object is used internally to point to the instance object 2 that is about to be generated. Uppercase letters, used to distinguish common functions
function Person (name) { the name=name}var person1=New person (' Xiaohong ') )var person2=New person (' Lili ')
Person1.constructor=person constructor points to constructors, person's built-in properties Person.prototype (function objects), each prototype object has a constructor property, Pointer to the function where the prototype property is located
namely Person1.constructor=person2.constructor=person.prototype.constructor
Inheriting through prototypes
Three. __proto__, each object has this property pointing to the prototype that created his constructor, which is Person1.__proto__=person.prototype
// var obj={} var obj=New Object (); Obj.constructor= = =objectobj.__proto__= = = Object.prototype
Person1.__proto__ is Person.prototype.
Person.__proto__ is a person is a constructor, function, or function.prototype
Person.prototype._proto__ is the Person.prototype is the prototype object, the objects, that is Object.prototype
Object.__proto__ is Objext is the structure of the number of rows function that is Function.prototype
OBJECT.PROTOTYPE.__PTOTO__ is the prototype of the Object.prototype's prototype object __proto__ to the constructor, which is null at the top level
Four. Math and JSON are math.__proto__===object.prototype that exist as objects
Five. Function.prototype is the only typeof Function.prototype is a Function prototype, and the prototype of other constructors are object
Six. Note the point of constructor for example
functionAnimal () {}animal.prototype.age= ' 20 'functionCat (name,color) { This. Name =name This. color =Color This. name2 = ' 11112222 '}cat.prototype=NewAnimal (); Cat.prototype.type= "Cat"Cat.prototype.eat=function() {Console.log (' Love to eat fish ')}functionDog (name) { This. name=name} Dog.prototype=NewAnimal ();D Og.prototype={getName:function() {Console.log (' Gougou ') }}
Cat.prototype.constructor = = = Animal Dog.prototype.constructor===object is not the same, the latter is rewrite Animal.prototype, the former is modified.
Seven.
- Prototype and prototype chain is a model of JS implementation inheritance.
- The formation of the prototype chain is really,
__proto__
rather thanprototype
JS prototype and prototype chain understanding constructor constructors