ES6 Map, number and string keys should map different objects

RESOLVED INVALID

Status

()

Firefox
Untriaged
RESOLVED INVALID
3 years ago
3 years ago

People

(Reporter: msnazi, Unassigned)

Tracking

33 Branch
x86
Mac OS X
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

3 years ago
Created attachment 8477961 [details]
Screen Shot 2014-08-23 at 8.20.22 PM.png

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36

Steps to reproduce:

m = new Map()
Map {  }
m[200] = "number 200"
m["200"] = "string 200"
console.log(m[200]); // returns "string 200"


Actual results:

map[200] returned "string 200"


Expected results:

map[200] should return "number 200" according to documentations here
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map

Comment 1

3 years ago
You can't access Map properties using [] notation, neither for setting nor for getting. So you're effectively doing:

m = new Object();
m[200] = "number 200"
m["200"] = "string 200"

in which case this is entirely expected.

If you were to do:

m = new Map();
m.set(200, "number 200");
m.set("200", "string 200");

then m.get(200) produces "number 200" as you would expect.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 3 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.