gpt4 book ai didi

javascript - 分配原型(prototype)后无法访问构造函数

转载 作者:行者123 更新时间:2023-11-29 21:56:23 24 4
gpt4 key购买 nike

<分区>

谁能解释一下为什么会这样

function Human(name) {
this.name = name;
}
var george = new Human('George');
alert(george.constructor === Human)

这说明是真的。而

var monkey = {
hair: true,
feeds: 'bananas',
breathes: 'air'
};

function Human(name) {
this.name = name;
}
Human.prototype = monkey;
var george = new Human('George');
alert(george.constructor === Human)

这显示错误

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com