子类继承父类原型解决方法:深拷贝、组合继承
1.深拷贝
//深拷贝 function deepCopy(obj) { let newObj = Array.isArray(obj) ? [] : {} for (const key in obj) { if (Object.hasOwnProperty.call(obj, key)) { if (typeof obj[key] == 'object') { newObj[key] = deepCopy(obj[key]) } else { newObj[key] = obj[key]; } } } return newObj }
Son.prototype = Dad.prototype
2.组合继承
let Link = function(){} Link.prototype = Dad.prototype Son.prototype = new Link() Son.prototype.constructor = Son
虚心学习、丰富自己