高分请教容易问题

zhagnujn 2004-05-06 07:50:10
1.
var a=b.prototype=new Component();
这句怎么理解,是不是表明a是b的超类,对象原型是什么?
2.
<script type="text/javascript">
function Compute_size()
{
alert(this.height);
return this.height*this.width;
}
function Rectangle()
{
this.height=1;
this.size=Compute_size();
this.height=3;
this.width=4;
}
var a=new Rectangle();
document.write(a.size(),"<br>");
</script>
在Rectangle的构造函数中调用函数Compute_size()为什么alert显示的值是3,而不是1?
...全文
33 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
fason 2004-05-08
  • 打赏
  • 举报
回复
b是个类型(类),a只不过是b的prototype的一个引用
zhagnujn 2004-05-08
  • 打赏
  • 举报
回复
第一个问题中,a和b是什么关系?
lhzyn 2004-05-08
  • 打赏
  • 举报
回复
this.height=1;//此时为1
this.width=4;
this.size=this.Compute_size();
this.height=3;//此时为3,最终为3
zhagnujn 2004-05-08
  • 打赏
  • 举报
回复
为什么没人帮我?
zhagnujn 2004-05-07
  • 打赏
  • 举报
回复
1。但是调用函数Compute_size()的时候this.height的值是1呀,只是在调用函数后才被赋为3。为什么在调用函数的过程中显示3?


2。如果只说b继承了Component,那么a是什么?
fason 2004-05-06
  • 打赏
  • 举报
回复
1.这里只是说b继承Component
2.
<script type="text/javascript">

function Rectangle()
{
this.height=1;
this.width=4;
this.size=this.Compute_size();
this.height=3;
}
Rectangle.prototype.Compute_size = function()
{
alert(this.height);
return this.height*this.width;
}
var a=new Rectangle();
document.write(a.size,"<br>");
52juanjuan 2004-05-06
  • 打赏
  • 举报
回复
this.height=1;
this.size=Compute_size();
this.height=3;
因为是同一个对象,所以你在给他付值之后变量了3,因此alert()的值也就是3了

87,997

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧