遵循Angular2快速入门指南,我们被指示包括es6-shim
2个地方:
1) index.html
<script src="node_modules/es6-shim/es6-shim.min.js"></script>
2) typings.json
"ambientDependencies": {
"es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#6697d6f7dadbf5773cb40ecda35a76027e0783b2"
}
Run Code Online (Sandbox Code Playgroud)
我的印象是我们正在编写es6
代码es5
.
配置 tsconfig.json
{
"compilerOptions": {
"target": "es5",
...
Run Code Online (Sandbox Code Playgroud)
如果最终结果是浏览器正在加载es5
,为什么浏览器需要垫片es6
?
对于我们的应用程序,我们需要使用新功能template string
.
var verLongKey= `834r845784576485
y84ery5845y485yu843
483y53485684576845
jhu87843647356756745==457485,mh
ererthe8t0998785==ery8`;
Run Code Online (Sandbox Code Playgroud)
但旧的浏览器(如Android默认浏览器)不支持模板字符串.
如何获得此功能的polyfill?尝试babel
.我们让这个polyfill适用于所有功能但是template string
.目前modernizr
用于检测支持和显示警报以使用其他浏览器.这种方法对用户来说很烦人.如何让一些polyfill在非支持的浏览器上运行?
是什么让我们这样template strings
.问题是我不能使用这些工具(trceur
,babel
),因为这个文件是在生产中生成的puppet
.我们无法在那里运行这些转发器.想在浏览器端添加一些polyfill.键中包含一些\n
需要保留它们的字符.我想要一些polyfill所以,我可以在configs js文件之前包含.
我在TypeScript中有以下代码:
export class Config
{
private options = new Map<string, string>();
constructor() {
}
public getOption(name: string): string {
return this.options[name]; // <-- This line causes the error.
}
}
Run Code Online (Sandbox Code Playgroud)
编译器给了我这个错误:
Error:(10, 16) TS7017: Index signature of object type implicitly has an 'any' type.
通过es6-shim可以"映射"地图.我不太清楚这里发生了什么.实际上这张地图让我有些困惑.Map应该来自es6-shim,它应该实现es6功能.但是es6没有静态类型,对吧?那么,为什么Map期望键/值类型作为泛型参数?我看到有些人添加'noImplicitAny'标志,但我想解决问题,而不是忽略它.
谢谢.
我正在尝试使用Angular 2,我注意到在使用*ng超过1500项时,Internet Explorer 11上的性能显着变慢.IE11大约需要25秒,而其他浏览器大约需要1秒.
暂停调试器我注意到代码不断调用es6-shim.js中的isNan函数.这里是调用堆栈:
这里有一个工作的plnkr:http://plnkr.co/edit/sEujClHmuCbrydIiYQYL?p = preview .代码很简单:
<ul *ngFor="#item of items">
<li>Item: {{item.itemKey}}</li>
</ul>
//Load items simulating remote load
setTimeout(function(){
for (let i = 0; i < 1500; i++) {
self.items.push(new Item(i+""));
}
},1000);
Run Code Online (Sandbox Code Playgroud)
有同样问题的人吗?任何改善性能的解决方法或提示?
先感谢您.
我在Twitter上提到,我是从移动es6-shim
到babel
.其他人提到:
即使有了巴贝尔,仍然需要垫片.他们修复破碎的内置物,巴贝尔的输出使用.
所以:
babel需要es6-shim还是类似?
如果确实如此,为什么不把require
这些东西当作依赖呢?
引用的答案优先于'是/否',没有支持参数!
es6-shim ×5
angular ×2
babeljs ×1
ecmascript-6 ×1
html5 ×1
javascript ×1
ngfor ×1
performance ×1
polyfills ×1
typescript ×1