Angular2为什么我们需要ES6-垫片 [英] Angular2 why do we need the es6-shim
问题描述
继 Angular2快速入门指南我们奉命包括 ES6-垫片
在两个地方:
Following the Angular2 Quickstart Guide we are instructed to include es6-shim
in 2 places:
1) index.html的
<脚本SRC =node_modules / ES6-垫片/ ES6-shim.min.js>< / SCRIPT>
2) typings.json
"ambientDependencies": {
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#6697d6f7dadbf5773cb40ecda35a76027e0783b2"
}
我的是,我们正在编制IM pression根据我们 ES6
code降至 ES5
。
在配置 tsconfig.json
{
"compilerOptions": {
"target": "es5",
...
如果最终的结果是,浏览器加载 ES5
,为什么浏览器需要为 ES6
垫片?
If the end result is that the browser is loading es5
, why does the browser needs shims for es6
?
推荐答案
分型是由你的编辑器来给你code提示/智能感知,和 ES6-shim.min.js
为code,模拟ES6对ES5的浏览器功能。其中一些功能是无极
, Array.from()
...
Typings are used by your editor to give you code hinting/intellisense, and es6-shim.min.js
is a code that emulates ES6 features for ES5 browsers. Some of those features are Promise
, Array.from()
...
当你的code被翻译成ES5,你需要包括 ES6-垫片
,所以你可以在其中使用这些新功能...考虑这个ES6 code:
While your code is translated to ES5, you need to include es6-shim
so you can use those new features in it... Consider this ES6 code:
let test1 = () => 123 + 456;
let test2 = new Promise((resolve, reject ) => {});
这将被转换为ES5 code:
it will be translated to ES5 code:
var test1 = function () { return 123 + 456; };
var test2 = new Promise(function (resolve, reject) { });
但没有 ES6-垫片
无极将是不确定的...
but without es6-shim
Promise would be undefined...
这篇关于Angular2为什么我们需要ES6-垫片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!