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{}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM