【发布时间】:2019-03-20 14:59:13
【问题描述】:
我是 javascript 新手,我正在尝试创建一个对象,然后我可以用它的实例填充一个列表。我有这个代码,但是有“这个”感觉是多余的。每一行的关键字。有没有更整洁/更合适的方法来创建这样的对象?
这是我当前的对象:
var Particle = function(x, y) {
this.x = x;
this.y = y;
this.xspeed = 0;
this.yspeed = 0;
this.xacc = 0;
this.yacc = 0;
this.update = function() {
this.x += this.xspeed;
this.y += this.yspeed;
this.xspeed += this.xacc;
this.yspeed += this.yacc;
}
}
提前感谢您的帮助
【问题讨论】:
标签: javascript function object methods