Object.prototype.clone = function(){
var res = Object.create(Object.getPrototypeOf(this))
var props = Object.getOwnPropertyNames(this)
props.forEach(function(item){
if(Object.prototype.toString.call(this[item]) ==="[object Object]" || Object.prototype.toString.call(this[item]) ==="[object Array]") return res[item] = this[item].clone()
des = Object.getOwnPropertyDescriptor(this, item)
Object.defineProperty(res, item, des)
}, this)
return res
}
原文:https://www.cnblogs.com/usebylgb/p/13553629.html