Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does ES6 define map.length==0?

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?

like image 864
jimm101 Avatar asked Oct 05 '15 18:10

jimm101


1 Answers

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).

like image 104
GOTO 0 Avatar answered Oct 24 '22 11:10

GOTO 0