对象Object.assign方法的兼容

有部分浏览器中没有Object.assign方法,则使用以下方式进行添加

if(typeof Object.assign != 'function') {
    (function() {
        Object.assign = function(target) {
            'use strict';
            if(target === undefined || target === null) {
                throw new TypeError('Cannot convert undefined or null to object');
            }

            var output = Object(target);
            for(var index = 1; index < arguments.length; index++) {
                var source = arguments[index];
                if(source !== undefined && source !== null) {
                    for(var nextKey in source) {
                        if(source.hasOwnProperty(nextKey)) {
                            output[nextKey] = source[nextKey];
                        }
                    }
                }
            }
            return output;
        };
    })();
}

你可能感兴趣的:(对象Object.assign方法的兼容)