62,047
社区成员
发帖
与我相关
我的任务
分享
<html>
<head>
<title></title>
<script>
function Rectangle(w,h)
{
this.width=w;//问题:this.width是相当与Rectangle.width还是Rectangle.prototype.width
this.height=h;
}
function test()
{
var rect=new Rectangle(5,10);
alert(rect.height);
}
test();
</script>
</head>
<body>
</body>
</html>
js中的简单问题(静态属性和实例属性):
function Rectangle(w,h)
{
this.width=w;//问题:this.width是相当与Rectangle.width还是Rectangle.prototype.width
this.height=h;
}
vat rect=new Rectangle(5,10);
如何调用:
Rectangle.width?
或
rect.width?
还是两者都可以?
function Rectangle(w, h)
{
this.width = w;
// 问题:this.width是相当与Rectangle.width还是Rectangle.prototype.width
this.height = h;
}
那就是说this.width是相当与Rectangle.prototype.width了?
<html>
<head>
<title></title>
<script>
function Rectangle(w, h)
{
this.width = w;
// 问题:this.width是相当与Rectangle.width还是Rectangle.prototype.width
this.height = h;
}
function test()
{
var rect = new Rectangle(5, 10);
alert(rect.height);
Rectangle.prototype.area = 50;
alert(rect.area);
}
test();
</script>
</head>
<body>
</body>
</html>