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: ƒ}

 

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

评论关闭
IT源码网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!