dragonfly
dragonfly

Reputation: 17773

ES6 Map features support - too big support in IE11?

I'm exploring ES6 few features. To check what is available and where I use:

http://kangax.github.io/compat-table/es6/

To play around I use Babel:

https://babeljs.io/repl

When exploring Map , compatibility table says that

constructor arguments are not supported in IE11

But I copied sample code:

var result = function() {
  var key1 = {};
  var key2 = {};
  var map = new Map([[key1, 123], [key2, 456]]);

  return map.has(key1) && map.get(key1) === 123 &&
         map.has(key2) && map.get(key2) === 456;
}();

console.log(result);

executed it in IE11 and to my surprise, result is true. true was both in Babel (although Babel didn't generate any code) and also in IE 11 console.

Why is that?

Upvotes: 3

Views: 1649

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074148

To play around I use Babel:

https://babeljs.io/repl

That's Babel using its Map polyfill in the REPL. If you run that code, verbatim, in IE11 itself, you get false, not true:

var result = function() {
  var key1 = {};
  var key2 = {};
  var map = new Map([[key1, 123], [key2, 456]]);

  return map.has(key1) && map.get(key1) === 123 &&
         map.has(key2) && map.get(key2) === 456;
}();

console.log(result);

Result in IE11:

enter image description here


(I was briefly thrown by the fact that in the REPL, if you console.log(Map), it shows function Map() { [native code] }. But logansfmyth was kind enough to confirm in a comment that Babel does that with shimmed functions if they conform to native behavior.)

Upvotes: 2

Related Questions