Reputation: 998
According to MDN:
Map.length
The value of the length property is 0.
What is the use case for this? I understand why Map.size
is semantically correct. But surely a Map.length
that almost always returns the "wrong" answer is a bad idea, especially if there's an oversight migrating code from ES5. Is there a way to force an error when this is used?
Upvotes: 8
Views: 1768
Reputation: 47791
Constructors in JavaScript are regular functions, and the length
property of a function corresponds to the number of formal parameters expected by the function, which is 0 in the case of Map
.
Contrast this with RegExp.length
, which is 2, because the RegExp
constructor expects two parameters (pattern and flags).
Upvotes: 15