六安做网站的,全国工业设计大赛官网,网站建设课程简介,cnzz wordpress插件带着问题看代码#xff1a; 1、原始的继承是怎样实现继承的#xff1f; A类的prototype 属性 B类的实例 2、实现继承后#xff0c;连B类的中实例的属性#xff08;放在了A类的prototype中#xff09;和原型链的上的东西都可以用 3、A.prototype.constructor实际上已经指向…带着问题看代码 1、原始的继承是怎样实现继承的 A类的prototype 属性 B类的实例 2、实现继承后连B类的中实例的属性放在了A类的prototype中和原型链的上的东西都可以用 3、A.prototype.constructor实际上已经指向了B–被重写了但是不影响对实际代码运行的理解 4、原型链继承是往上找找到了直接就用了就不再往上找了
function subType (j) {this.name subTypethis.nameJ j
}
subType.prototype.getValue function () {return subType原型上的值
}function deviceType (k) {this.nameOther deviceTyethis.nameK k
}
// 这种方法实现的继承就是连constructor中的属性就也给继承了
deviceType.prototype new subType()
deviceType.prototype.getValueOther function() {return deviceType原型链上的值
}let instance new deviceType(99)// 继承的表现可以看到自己原型上的和继承某个实例对象原型链上的东西
console.log(instance.nameOther) // deviceTye
console.log(instance.name) // subType
console.log(instance.getValueOther()) // deviceType原型链上的值
console.log(instance.getValue()) // subType原型上的值// 这行打印可以看到是怎样的继承某个实例的属性会放在deviceType.prototype.
console.log(instance.__proto__) // { name: subType, getValueOther: [Function (anonymous)] }// 会发现被重写了
console.log(instance.constructor) // [Function: subType]
// 打印一下完整的原型链
console.log(instance.__proto__.__proto__.constructor) // [Function: subType]// 虽然被重写了但是不影响实例化
console.log(instance.nameK) // 99
console.log(instance.nameJ) // undefined