javascript - 为什么日志中的 F.prototype 属性不一致
问题描述
所以函数是对象类型的,所以可以有属性。默认情况下,函数 F 将具有名称、长度和原型属性,并且原型属性将默认设置为一个对象,该对象具有一个指向函数本身的键“构造函数”。IE
function F() {
this.foo = "bar";
}
/* default prototype
F.prototype = { constructor: F};
*/
这可以通过运行console.log(Object.getOwnPropertyDescriptors(F.prototype));
哪些输出来证明
{
constructor: {
value: [Function: F],
writable: true,
enumerable: false,
configurable: true
}
}
并且F.prototype.constructor == F
评估为真。
令人困惑的是,它console.log(F.prototype);
只会输出一个空对象F {}
同样console.log(Object.getOwnPropertyDescriptors(F));
会产生以下内容:
{
length: { value: 0, writable: false, enumerable: false, configurable: true },
name: {
value: 'F',
writable: false,
enumerable: false,
configurable: true
},
prototype: {
value: F {},
writable: true,
enumerable: false,
configurable: false
}
}
F {}
为什么当我期望类似的东西时这些返回一个空对象{ constructor: [Function: F] }
?
解决方案
推荐阅读
- python - scipy.stats.binom 和 np.random.binomial 之间的区别
- angular - Primeng virtualscroll offset 像 peagination
- android - Cordova 媒体插件 - 加载本地文件/blob - 错误代码“未定义”
- javascript - 我正在尝试让不和谐的机器人收到此错误 [Symbol(code)]: 'BITFIELD_INVALID'
- python - “返回”值的作用和程序的意外结果
- javascript - App Script 如何使用 Utilities.getUuid(); 供用户同时使用
- linux - 以编程方式重启 sdio 是否可行?
- python - 如果只有黑色和白色(没有灰色),是否有必要对像素值进行归一化?
- numba - 如何在pypy3上安装numba,或者pypy3不支持numba?
- spring-boot - 会话并发不适用于 Spring Security