function hex(x,y,side,isLast,color)
{//Hex object constructor.
this.x = x;
this.y = y;
this.side = side;
this.isLast = isLast;
this.color = color;
function multiply()
{
return this.x * this.y;
}
this.multiply = multiply;
}
var hexagon = new hex(22,22,20,0,1);
document.write(hexagon.multiply);
加载index.htm时,结果在屏幕上写入函数而不是返回值:
function multiply(){return this.x*this.y; }
:(
你忘记了():
document.write(hexagon.multiply());
Run Code Online (Sandbox Code Playgroud)
如果你不使用(),Javascript将把它multiply作为变量处理并写出它的内容 - 在这种情况下,是函数的代码.
| 归档时间: |
|
| 查看次数: |
2135 次 |
| 最近记录: |