【发布时间】:2015-07-27 20:54:00
【问题描述】:
我知道我可以通过以下方式添加方法:
point.prototype.move = function ()
{
this.x += 1;
}
但是,有没有办法通过将在其外部声明的函数分配给其属性之一来向类添加方法? 我很确定这行不通,但它让我知道我正在尝试做什么:
function point(x, y)
{
this.x = x;
this.y = y;
this.move = move();
}
function move()
{
this.x += 1;
}
【问题讨论】:
-
嗯,你测试了吗?
标签: javascript methods