var a = Function.length,b = new Function().length
a === b
输出false.
b = 0这个没有疑问,问题是a,这里找到了一个参考,里面也没说原因,以后有时间可以再研究
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Function/length
Function 构造器的属性节
Function 构造器本身也是个Function。他的 length 属性值为 1 。该属性 Writable: false, Enumerable: false, Configurable: true.
Function.prototype 对象的属性节
Function.prototype 对象的 length 属性值为 0
console.log(Function.length); /* 1 */
console.log((function() {}).length); /* 0 */
console.log((function(a) {}).length); /* 1 */
console.log((function(a, b) {}).length); /* 2 etc. */
console.log((function(...args) {}).length);
// 0, rest parameter is not counted
console.log((function(a, b = 1, c) {}).length);
// 1, only parameters before the first one with
// a default value is counted
44个javascript问题-37(来自知乎)
最新推荐文章于 2020-09-30 11:12:43 发布