Prototype Inheritance

function Obj3(z){
  this.z = z;
  this.f3 = function(){alert('I was defined in Obj3')};
  this.getZ = function(){alert(this.z)};
}

function Obj2(y,z){
  this.y = y;
  Obj3.call(this, z);
  this.f2 = function(){alert('I was defined in Obj2')};
  this.getY = function(){alert(this.y)};
}
Obj2.prototype = new Obj3();
Obj2.prototype.constructor = Obj2;

function Obj1(x,y,z){
  Obj2.call(this,y,z);
  this.x = x;
  this.f1 = function(){alert('I was defined in Obj1')};
  this.getX = function(){alert(this.x)};
}

Obj1.prototype = new Obj2();
Obj1.prototype.constructor = Obj1;
Obj1.prototype.toString = function(){
  return "obj1111";
}

var o = new Obj1(1,2,3);

o.getX();
o.getY();
o.getZ();
var b = new Obj2(5,6);
//alert(b instanceof Obj1);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值