Angular 角度2为什么我们需要es6垫片
按照说明,我们被指示在两处包括Angular 角度2为什么我们需要es6垫片,angular,es6-shim,Angular,Es6 Shim,按照说明,我们被指示在两处包括es6垫片: 1) index.html 2) typings.json "ambientDependencies": { "es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#6697d6f7dadbf5773cb40ecda35a76027e0783b2" } { "compilerOptions": { "target": "es5",
es6垫片
:
1) index.html
2) typings.json
"ambientDependencies": {
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#6697d6f7dadbf5773cb40ecda35a76027e0783b2"
}
{
"compilerOptions": {
"target": "es5",
...
我的印象是,我们正在将es6
代码编译为es5
在tsconfig.json中配置
"ambientDependencies": {
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#6697d6f7dadbf5773cb40ecda35a76027e0783b2"
}
{
"compilerOptions": {
"target": "es5",
...
如果最终结果是浏览器正在加载es5
,为什么浏览器需要es6
垫片 编辑器使用键入为您提供代码提示/intellisense,es6 shim.min.js
是一种模拟ES5浏览器的es6功能的代码。其中一些功能是Promise
,Array.from()
当您的代码转换为ES5时,您需要包括es6垫片
,以便在其中使用这些新功能。。。考虑这个ES6代码:
let test1 = () => 123 + 456;
let test2 = new Promise((resolve, reject ) => {});
它将转换为ES5代码:
var test1 = function () { return 123 + 456; };
var test2 = new Promise(function (resolve, reject) { });
但是如果没有es6垫片
承诺将是未定义的…TypeScript没有内置的多边形填充。有些功能是不可传输的,这就是像es shim
这样的多填充的作用
TypeScript定义文件将在您选择的编辑器中为您提供键入支持,es shim
将提供TypeScript无法转换为ES5代码的功能的实现
TypeScript不可传输的一些功能包括:
- 许诺
- 挂起原型对象的函数(
Array.from()
,Array.of()
,Number.isInteger()
,等等)
- 模块加载
一般做法是:
经验法则是,如果有一个规范/理智的发射没有巨大的性能影响,我们将尝试支持它。我们不添加任何运行时方法或数据结构,而core.js(或任何pollyfil)的作用更大
你的意思是编辑给出的hinting/intellisense
正在使用es6垫片吗?截至2016年10月,他们现在在OP参考的快速入门中推荐core js而不是es6垫片。