<script>
//冒充对象继承:把父类私有的+公有的克隆一份一模一样的 给子类私有的
function A() {
this.x = 100;
}
A.prototype.getX = function () {
console.log(this.x);
};
function B(){
var temp = new A;
for(var key in temp){
console.log(key);
this[key] = temp[key];
}
temp = null;
}
var n = new B;
console.log(n.x);
n.getX();//这回getX这个方法成为了B私有的 不在prototype上
</script>
冒充对象继承
最新推荐文章于 2021-08-01 12:38:09 发布