Why does ES6 define map.length == 0?

According to MDN :

Map.length

The value of the length property is 0.

What is the precedent for this? I understand why Map.size is semantically correct. But of course, Map.length , which almost always returns the β€œwrong” answer, is a bad idea, especially if there is an add-in that transfers code from ES5. Is there a way to make an error when it is used?

+7
javascript ecmascript-6
source share
1 answer

Constructors in JavaScript are regular functions, and the length property of the 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 (template and flags).

+15
source share

All Articles