Open newPromise opened 6 years ago
function person ( { name, home } ) { } Object.assign( person.prototype, { showConstructor () { console.log( this.constructor ); // 指向 person } })
使用 下面这种方法,情况不会向我们想的那样:
person.prototype = { showConstructor () { console.log( this.constructor ); // Object } }
使用上面的这种方法,person.prototype 成为了一个对象,当然,对象的构造函数就是指向对象了
person.prototype
使用 下面这种方法,情况不会向我们想的那样:
使用上面的这种方法,
person.prototype
成为了一个对象,当然,对象的构造函数就是指向对象了