<script>
//寄生组合模式继承 为了解决混合模式继承中 用原型继承会把父类公有的变成子类私有的,而继续使用call把父类私有的拿到子类私有的当中,这样子类私有的以及公有的中都会有某些数值.
function A() {
this.x = 100;
}
A.prototype.getX = function () {
console.log(this.x);
};
function B() {
A.call(this);
}
B.prototype = Object.create(A.prototype);
B.prototype.constructor = B;
var n = new B;
n.getX();
//处理兼容问题
function objectCreate(o) {
function fn() {
fn.prototype = o;
return new fn;
}
}
</script>
寄生混合模式继承
最新推荐文章于 2021-10-23 23:21:25 发布