gpt4 book ai didi

javascript - 从构造函数返回的对象没有原型(prototype)

转载 作者:行者123 更新时间:2023-11-30 00:01:37 26 4
gpt4 key购买 nike

<分区>

我在Eloquent JavaScript这本精彩的书中看到了这段话:

Constructors (in fact, all functions) automatically get a property named prototype, which by default holds a plain, empty object that derives from Object.prototype. Every instance created with this constructor will have this object as its prototype.

所以我想我会测试一下。

function Person () {}

person = new Person()

console.log(Person.prototype) // Object {}
console.log(person.prototype) // undefined ???? :O

第一个console.log是有道理的,但为什么第二个显示undefined

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