Javascript显示功能文本而不是在屏幕上打印值

Gab*_*lla 0 javascript

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; }

:(

Pek*_*ica 6

你忘记了():

document.write(hexagon.multiply());
Run Code Online (Sandbox Code Playgroud)

如果你不使用(),Javascript将把它multiply作为变量处理并写出它的内容 - 在这种情况下,是函数的代码.