gpt4 book ai didi

javascript - 在 JavaScript 中,函数原型(prototype)属性的默认值是多少?

转载 作者:行者123 更新时间:2023-11-30 12:02:39 24 4
gpt4 key购买 nike

在 Chrome 的 JavaScript 控制台中:

function placeOrder() {
return 1;
};
undefined
console.log(placeOrder.prototype);
placeOrder {}

但在 IE 11 中,默认的原型(prototype)属性似乎是一个空对象。我想知道 Chrome 中的对象“placeOrder {}”是什么?我还在 Firefox 中测试过它。在 Firefox 中,原型(prototype)属性也是“placeOrder {}”。

在 IE 11 控制台中:

function placeOrder() {
return 1;
};
undefined
console.log(placeOrder.prototype);
undefined
[object Object]{}

谢谢。

最佳答案

它是一个对象,它继承自 Object.prototype 并具有自己的 constructor 属性,其值为构造函数。

参见 Creating Function Objects

  1. Let proto be the result of creating a new object as would be constructed by the expression new Object() where Object is the standard built-in constructor with that name.
  2. Call the [[DefineOwnProperty]] internal method of proto with arguments "constructor", Property Descriptor {[[Value]]: F, { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}, and false.
  3. Call the [[DefineOwnProperty]] internal method of F with arguments "prototype", Property Descriptor {[[Value]]: proto, { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false}, and false.

关于javascript - 在 JavaScript 中,函数原型(prototype)属性的默认值是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36240654/

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