Function.prototype
是唯一一个没有prototype
属性的函数吗?
为什么该属性不存在,而不是具有值为null
的prototype
属性。
document.write(Object.getOwnPropertyNames(Function.prototype));
编辑:假设prototype
属性被省略,因为它没有[[Construct]]
内部方法(它不是一个构造函数)。
发布于 2016-07-16 13:08:37
啊,刚刚发现section 9.3第6段说:
非构造函数的
内置函数没有prototype属性,除非在特定函数的说明中另有指定。
所有“正常”函数都有[[Construct]]
内部方法(section 9.2.3):
如果functionKind为"normal",则needsConstruct为true。
奇怪的内置函数可能有也可能没有[[Construct]]
内部方法,如果它们没有,那么它们就没有prototype
属性,“除非另有说明”。
发布于 2016-07-16 13:29:39
只有构造函数才有prototype
property
可用作构造函数的
函数实例具有
prototype
属性。
除了Function.prototype
之外,还有多个非构造函数的示例,例如
Math
对象中的
Math.pow中的Math.pow;// "function“'prototype‘;// false
typeof document.createElement('object');// "function“'prototype‘in document.createElement('object');// false
typeof (x => x* x);// "function“'prototype‘in (x => x* x);// false
https://stackoverflow.com/questions/38411387
复制