直接上代码
/**
* Created by Norway on 2019/10/28.
*/
//深拷贝start
function deepCopy(obj) {
if(typeof obj !== "object"){
return obj;
}
var myObj = obj instanceof Object ? {} : [];
for( var key in obj){
myObj[key] = typeof obj[key] !== "object" ? obj[key] : deepCopy(obj[key]);
}
return myObj;
}
//深拷贝end
//new命令start
function New(func) {
var res ={};
if(func.prototype !== null){
res.__proto__ = func.prototype;
}
var ret = func.apply(res,Array.prototype.slice.call(arguments,1));
if(typeof ret ==='object' || typeof ret === "function" &&ret !== null){
return ret;
}
return res;
}
function Person(name,age) {
this.name = name;
this.age =age;
}
Person.prototype.show = function () {
console.log(this.name+this.age)
}
//new命令end