直接复制拿去IE大佬上面用一下就可以了,兄嘚。
// IE 兼容方法 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; }; } // 以下为测试代码 var target = { a: 1, b: 2 }; var source = { b: 4, c: 5 }; var returnedTarget = Object.assign(target, source); console.log(target); // expected output: Object { a: 1, b: 4, c: 5 } console.log(returnedTarget); // expected output: Object { a: 1, b: 4, c: 5 }
原文地址:https://www.cnblogs.com/wen233/p/11269258.html
时间: 2024-10-09 00:16:39