[英]ES6 Map features support - too big support in IE11?
I'm exploring ES6 few features. 我正在探索ES6的一些功能。 To check what is available and where I use:
检查可用的内容和使用位置:
http://kangax.github.io/compat-table/es6/ http://kangax.github.io/compat-table/es6/
To play around I use Babel: 要玩弄我使用Babel:
https://babeljs.io/repl https://babeljs.io/repl
When exploring Map
, compatibility table says that 在探索
Map
,兼容性表说明了这一点
constructor arguments are not supported in IE11
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 . 在IE11中执行它,令我惊讶的是,结果是真的 。 true was both in Babel (although Babel didn't generate any code) and also in IE 11 console.
真的是Babel(虽然Babel没有生成任何代码)和IE 11控制台。
Why is that? 这是为什么?
To play around I use Babel:
要玩弄我使用Babel:
That's Babel using its Map
polyfill in the REPL. 这是Babel在REPL中使用
Map
polyfill。 If you run that code, verbatim, in IE11 itself, you get false
, not true
: 如果您在IE11本身中逐字地运行该代码,则会出现
false
,而不是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: 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.) (在REPL中,如果你使用
console.log(Map)
,它会显示function Map() { [native code] }
。但是logansfmyth很友好地在评论中证实了 Babel这样做如果符合本机行为,则调整函数。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.