zhou363667565
悠悠隐于市
2011-12-27 10:23

JS 中prototype 的问题

  • js

[code="java"]
//Object对象的inObj设置为1;
Object.prototype.inObj = 1;

//定义A类;
function A(){
//给属性设置值为2;
this.inA = 2;
}

//给A类的inAproto属性设置为3;
A.prototype.inAProto = 3;

//这下面两句是什么意思?
B.prototype = new A();
B.prototype.constructor = B;

//定义B类;
function B(){
//给B类属性设置值为4;
this.inB = 4;
}

B.prototype.inBroto = 5;

x = new B;
document.write(x.inObj+","+x.inA+","+x.inAProto+","+x.inB+","+x.inBroto);
[/code]

//这下面两句是什么意思?
[b]B.prototype = new A();
B.prototype.constructor = B;[/b]

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答