JS 对象API之获取原型对象

1、从 构造函数 获得 原型对象:

构造函数.prototype

2、 对象实例 获得 父级原型对象

方法一: 对象实例.__proto__        【 有兼容性问题,不建议使用】

方法二:Object.getPrototypeOf( 对象实例 )

 

代码栗子:

function Student(){
    this.name = "小马扎"; 
    this.age = 18;
}
var lilei = new Student();  // 创建对象实例
console.log(Student.prototype);  //Student{}
console.log(lilei.__proto__);  //Student{}
console.log(Object.getPrototypeOf(lilei));    //Student{}

 

posted @ 2017-12-19 17:07  狂奔的小马扎  阅读(4657)  评论(0编辑  收藏  举报