为什么Object.assign在Safari 8.0.7中似乎不起作用? [英] Why does Object.assign not appear to work on Safari 8.0.7?

查看:132
本文介绍了为什么Object.assign在Safari 8.0.7中似乎不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用webpack和babel-core编写一个应用程序 5.8.25

We're writing an app using webpack and babel-core 5.8.25.

在时间上,发生这种情况:

At one point in time, this happens:

someArray.map(item => {
  const updatedItem = Object.assign({}, item); // silently fails here... doesn't even continue the code

  updatedItem.prop = 'something cool';
});

这显然是在浏览器之前编译的。它适用于最新版本的Chrome和最新版本的iOS Safari,但在Safari 8.0.7 中,它会以静默方式失败(没有错误抛出...只是不

This is obviously compiled before hitting the browser. It works in the latest version of Chrome and the latest version of iOS Safari, but in Safari 8.0.7, it fails silently (no error thrown... just doesn't go past that line).

然而,这可以按预期(使用lodash)工作:

This, however, works as expected (using lodash):

someArray.map(item => {
  const updatedItem = _.extend({}, item); // the important part

  updatedItem.prop = 'something cool';
});

任何想法?我试图在互联网上戳这个,但是没有用。

Any idea? I tried poking around the internet regarding this, but to no avail.

推荐答案

Object.assign 适用于Chrome,因为Chrome本机支持。 babel-loader 仅将ES6语法转换为ES5语法,它不会使ES6库功能可用。使用Webpack来做最简单的方法是从你的配置改变你的配置,如

Object.assign works in Chrome because Chrome supports it natively. babel-loader on its own only converts ES6 syntax to ES5 syntax, it does not do anything to make ES6 library functionality available. The easiest way to do that with Webpack is to change your config from something like

entry: 'app.js'

to

entry: ['babel-core/polyfill', 'app.js']

// Or with Babel 6:
entry: ['babel-polyfill', 'app.js']

,以便Webpack还会在执行应用程序之前捆绑并运行polyfill。 Babel提供 / polyfill 作为一种简单的方式来加载聚合物填充物,但它是可选的,因为不是每个人都想使用它,并且因为有许多可用的Polyfill,而且Babel使用, core-js 只是其中一个。

so that Webpack will also bundle and run the polyfill before executing your application. Babel provides /polyfill as an easy way to load the polfill, but it is optional because not everyone wants to use it, and because there are many polyfills available and the one Babel uses, core-js is just one of many.

这篇关于为什么Object.assign在Safari 8.0.7中似乎不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆