JS 8-2 再谈原型

 

var bosn = new Student创建了Student的实例bosn。
bosn的原型(__proto__)指向构造器Student的prototype属性。

Student.prototype = Object.create(Peroson.prototype)
Student.prototype.constructor = Student;
Student.prototype是一个空对象,空对象的原型(__proto__)指向Peroson.prototype。

Person.prototype是一个内置的对象,本身也有自己的原型为Object.prototype

var obj = {x:1}
Object.getPrototypeOf(obj) === Object.prototype//true
getPrototypeOf方法:获取obj的原型

posted @ 2018-09-12 19:55  Chris_在IT道路上前行  阅读(89)  评论(0编辑  收藏  举报