Today I encountered a problem with anonymous functions:
(function() {}).length; // 0
(function(a,b) {}).length; // 2
Why do anonymous functions have the same number of length and formal parameters?
Today I encountered a problem with anonymous functions:
(function() {}).length; // 0
(function(a,b) {}).length; // 2
Why do anonymous functions have the same number of length and formal parameters?
the answer is here: length is an attribute value of a function object, indicating how many parameters the function must pass in, that is, the number of formal parameters.
`Function.length-JavaScript | MDN
https://developer.mozilla.org.`
has nothing to do with anonymity. Function.length
indicates the number of formal parameters of the function
function and arguments have the length attribute,
The length ofarguments object mainly reflects the number of arguments,
The length offunction mainly reflects the number of formal parameters,
but since JavaScript 1.4, the arguments.length property has been discarded
Previous: Python basic data structure dict inherits from object, but why is it a subclass of MutableMapping