core-jsJavaScript 的模块化标准库
core-js 是 babel-polyfill 的底层依赖,通过各种奇技淫巧,用 ES3 实现了大部分的 ES2017 原生标准库,同时还要严格遵循规范。
import 'core-js'; // <- at the top of your entry point Array.from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3] [1, [2, 3], [4, [5]]].flat(2); // => [1, 2, 3, 4, 5] Promise.resolve(32).then(x => console.log(x)); // => 32
没有全域命名空间污染:
import from from 'core-js-pure/features/array/from'; import flat from 'core-js-pure/features/array/flat'; import Set from 'core-js-pure/features/set'; import Promise from 'core-js-pure/features/promise'; from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3] flat([1, [2, 3], [4, [5]]], 2); // => [1, 2, 3, 4, 5] Promise.resolve(32).then(x => console.log(x)); // => 32
经过测试并支持的平台
-
Chrome 26+
-
Firefox 4+
-
Safari 5+
-
Opera 12+
-
Internet Explorer 6+ (sure, IE8- with ES3 limitations)
-
Edge
-
Android Browser 2.3+
-
iOS Safari 5.1+
-
PhantomJS 1.9 / 2.1
-
NodeJS 0.8+
评论