1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| function Ming(name, age){ Person.call(this, name, age); }
deepCopy(Ming.prototype,Person.prototype);
Ming.prototype.constructor = Ming;
function deepCopy(source){ let result = null; let type = checkType(source); if(type === 'Object'){ result = {}; }else if(type === 'Array'){ result = []; }else{ return result; } for(let i in source){ let value = source[i]; if(checkType(value) === 'Object' || checkType(value) === 'Array'){ result[i] = deepCopy(value); }else{ result[i] = value; } } return result; }
function checkType(obj){ return Object.prototype.toString.call(obj).slice(8, -1); }
|