一.對象:普通對象 函數對象函數
二.構造函數特色:1.須要new實例化,內部使用this對象指向即將要生成的實例對象 2.首字母大寫,用於區分普通函數this
function Person(name){ this.name=name } var person1=new Person('xiaohong') var person2=new Person('lili')
person1.constructor=Person constructor指向構造函數,Person的內置屬性 Person.prototype(函數對象),每一個原型對象都有一個constructor屬性,指向prototype屬性所在的函數Personspa
即person1.constructor=person2.constructor=Person.prototype.constructorprototype
經過原型實現繼承code
三.__proto__,每一個對象都有這個屬性指向建立他的構造函數的原型即person1.__proto__=Person.prototype對象
//var obj={} var obj=new Object(); obj.constructor===Object obj.__proto__===Object.prototype
person1.__proto__是Person.prototypeblog
Person.__proto__是Person是構造函數,Function,即Function.prototype繼承
Person.prototype._proto__是 Person.prototype是原型對象,Object,即Object.prototype原型鏈
Object.__proto__是 Objext是構造行數Function 即Function.prototypeget
Object.prototype.__ptoto__是 Object.prototype的原型對象的__proto__指向構造函數的prototype,處於頂層是null
四。Math和Json是以對象存在的 即Math.__proto__===Object.prototype
五。Function.prototype是惟一一個typeof Function.prototype是function的prototype,其餘構造器的prototype都是object
六。注意constructor的指向例如
function Animal(){ } Animal.prototype.age='20' function Cat(name,color){ this.name = name this.color = color this.name2 = '11112222' } Cat.prototype = new Animal(); Cat.prototype.type="貓" Cat.prototype.eat=function(){ console.log('愛吃魚') } function Dog(name){ this.name=name } Dog.prototype = new Animal(); Dog.prototype={ getName:function(){ console.log('gougou') } }
Cat.prototype.constructor === Animal Dog.prototype.constructor===Object 二者不相同,後者是重寫Animal.prototype,前者是修改。
七。
__proto__
而非prototype