最近新写的APP页面加入了bscroll.min.js插件文件,里面使用到了object.assign(),该方法ES6中合并对象用的。在比较新的手机上滑动页面没问题,但在较低版本的手机时滑动却没反应,查看日志发现有这么一句话:object.assign()
is not a function.才发现低版本浏览器不兼容问题。
解决办法
在使用有object.assign()的代码块/插件文件前加入以下代码:
if (typeof Object.assign != 'function') {
Object.assign = function(target) {
'use strict';
if (target == null) {
throw new TypeError('Cannot convert undefined or null to object');
}
target = Object(target);
for (var index = 1; index < arguments.length; index++) {
var source = arguments[index];
if (source != null) {
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
}
return target;
};
}
来源:CSDN
作者:Vincent_Wilk
链接:https://blog.csdn.net/Vincent_Wilk/article/details/104758356