加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular2为什么我们需要es6-shim

发布时间:2020-12-17 07:45:04 所属栏目:安全 来源:网络整理
导读:在 Angular2 Quickstart Guide之后,我们被指示将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/DefinitelyType
在 Angular2 Quickstart Guide之后,我们被指示将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"
}

我的印象是我们正在将我们的es6代码编译成es5.

在tsconfig.json中配置

{
  "compilerOptions": {
    "target": "es5",...

如果最终结果是浏览器正在加载es5,为什么浏览器需要es6的垫片?

您的编辑器使用打字来为您提供代码提示/智能感知,es6-shim.min.js是一个模拟ES5浏览器ES6功能的代码.其中一些功能是Promise,Array.from()…

虽然您的代码被转换为ES5,您需要包含es6-shim,以便您可以使用这些新功能…考虑这个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-shim承诺将是未定义的…

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读