if(typeofObject.assign != 'function'){
Object.assign = function(target){
'use strict';
if(target == null){
thrownewTypeError('Cannot convert undefined or null to object');
}
target = Object(target);
for(var index = 1, len = arguments.length; index < len; 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;
}
}
复制代码
create
if (typeofObject.create !== "function") {
Object.create = function (proto, propertiesObject) {
if (!(proto === null || typeof proto === "object" || typeof proto === "function")) {
throwTypeError('Argument must be an object, or null');
}
var temp = newObject();
temp.__proto__ = proto;
if(typeof propertiesObject ==="object"){
Object.defineProperties(temp,propertiesObject);
}
return temp;
}
}
复制代码
deepFreeze
functiondeepFreeze(obj){
var o, key;
Object.freeze(obj);
for(key in obj){
o = obj[key];
if( !(o.hasOwnProperty(key)) || !(typeof o === 'object') || Object.isFreeze( o ) ){
continue;
}
deepFreeze(o);
}
}
复制代码
is
if(typeofObject.js !== 'function'){
Object.is = function (x, y){
if(x === y){
// +0 != -0return x !== 0 || 1/x !== 1/y;
}else{
// NaN == NaNreturn x !== x && y !== y;
}
}
}
复制代码