【发布时间】:2012-12-12 14:37:04
【问题描述】:
什么是函数、数组和对象构造函数的长度静态属性?
静态方法是有意义的,但是长度静态属性呢?
Object.getOwnPropertyNames(Array)
["length", "name", "arguments", "caller", "prototype", "isArray"]
Object.getOwnPropertyNames(Function)
["length", "name", "arguments", "caller", "prototype"]
注意:我得到了关于 Function.prototype 的长度属性的答案,这里没有询问。
Object.getOwnPropertyNames(Function.prototype)
["length", "name", "arguments", "caller", "constructor", "bind", "toString", "call", "apply"]
Object.getOwnPropertyNames(Object)
["length", "name", "arguments", "caller", "prototype", "keys", "create", "defineProperty", "defineProperties", "freeze", "getPrototypeOf", "getOwnPropertyDescriptor", "getOwnPropertyNames", "is", "isExtensible", "isFrozen", "isSealed", "preventExtensions", "seal"]
【问题讨论】:
-
ECMA-262 第 3 版,第 15.2.3、15.3.3 和 15.4.3 部分指定所有这些构造函数有一个
length属性,其值为1。 -
感谢您的澄清 :) 但为什么 1 有任何具体原因?
标签: javascript oop semantics