Object.assign is not a function

后端 未结 2 2039
梦谈多话
梦谈多话 2020-12-09 04:41

I\'m using babel with gulp and create a simple DOM library in ES6. But after running and when i\'m going to use it, I got the Object.assign is not a function in

相关标签:
2条回答
  • 2020-12-09 05:32
    1. Install babel-core:

    $ npm install babel-core --save-dev

    1. Import polyfill module into your js:

    import 'babel-core/polyfill';

    1. Use babel to compile your code!
    0 讨论(0)
  • 2020-12-09 05:41

    As I suspect you already know, Google Chrome uses V8, which supports ECMAScript 5th edition. Object.assign is introduced in ECMAScript 6th edition.

    In order to use these additions, you need to include the ES6 polyfill provided by Babel:

    This will emulate a full ES6 environment. [...]

    Available from the browser-polyfill.js file within a babel-core npm release. This needs to be included before all your compiled Babel code. You can either prepend it to your compiled code or include it in a <script> before it.

    0 讨论(0)
提交回复
热议问题