When I run this code on console:
(function test(){
console.log(function(){}.apply.length);
})();
The output is: 2
I read about Function length. I understand the function length section on MDN. But I don't understand this. There are no parameters in function. Why is the output 2?
It's because you're asking for the .length of Function.prototype.apply, which is 2 for its thisArg and its argArray.
19.2.3.1Function.prototype.apply ( thisArg, argArray ) <-- two parameters
Because of apply which accepts 2 parameters. Without apply it will show 0
(function test() {
console.log(function() {}.length)
})();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With