怎样获取当前对象的原型对象prototype

1. 使用 Object.getPrototypeOf();

function Person(name){
    this.name = name;
}

var lilei = new Person("Lilei");
Object.getPrototypeOf(lilei); // {constructor: ƒ}

lilei.constructor.prototype; // {constructor: f}

 

2. 使用 obj.constructor.prototype;

function Person(name){
    this.name = name;
}

var lilei = new Person("Lilei");
lilei.constructor.prototype; // {constructor: ƒ}

 

3. 使用obj.__proto__;

function Person(name){
    this.name = name;
}

var lilei = new Person("Lilei");
lilei.__proto__; // {constructor: ƒ}

 

三种方法中, 第一种是最靠谱的, 后面两种都不太靠谱.

posted on 2019-10-14 21:54  aisowe  阅读(1149)  评论(1编辑  收藏  举报

导航