简体   繁体   中英

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?

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:

在此输入图像描述


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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM