Angular2 why do we need the es6-shim

后端 未结 2 1031
灰色年华
灰色年华 2021-02-07 03:27

Following the Angular2 Quickstart Guide we are instructed to include es6-shim in 2 places:

1) index.html

2条回答
  •  星月不相逢
    2021-02-07 03:49

    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()...

    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 ) => {});
    

    it will be translated to ES5 code:

    var test1 = function () { return 123 + 456; };
    var test2 = new Promise(function (resolve, reject) { });
    

    but without es6-shim Promise would be undefined...

提交回复
热议问题