Javascript ES6中的方法原型

Javascript ES6中的方法原型,javascript,Javascript,我想用ES6写这篇文章,但是我被卡住了,需要你的帮助。 当我使用ES6 do declare我的方法时,方法原型给了我以下错误: 未捕获的TypeError:无法在planesJS.js:238处设置未定义的属性“move” 这是原型: SI.SpaceShip.prototype.move = function (deltaX, deltaY) { this.x += deltaX; if(this.x <= 0) { this.x = 0; }

我想用ES6写这篇文章,但是我被卡住了,需要你的帮助。 当我使用ES6 do declare我的方法时,方法原型给了我以下错误:

未捕获的TypeError:无法在planesJS.js:238处设置未定义的属性“move”

这是原型:

SI.SpaceShip.prototype.move = function (deltaX, deltaY) {
    this.x += deltaX;
    if(this.x <= 0) {
        this.x = 0;
    }
    else if(this.x >= SI.Sizes.width - this.width) {
        this.x = SI.Sizes.width - this.width;
    }

    this.y += deltaY;
    if(this.y <= 0) {
        this.y = 0;
    }
    else if(this.y >= SI.Sizes.height - this.height) {
        this.x = SI.Sizes.height - this.height;
    }
}
SI.SpaceShip.prototype.move=函数(deltaX,deltaY){
此.x+=deltaX;
if(this.x=SI.size.width-this.width){
this.x=SI.size.width-this.width;
}
这个.y+=deltaY;
if(this.y=SI.size.height-this.height){
this.x=SI.size.height-this.height;
}
}

箭头函数没有原型,不能用作对象构造函数。看

箭头函数表达式[…]没有自己的表达式, 参数,超级,或新建。目标。这些函数表达式最适合于非方法函数,它们不能用作构造函数

你可以这样修理它

SI.SpaceShip = function (options) { ...

如果您想迁移到ES6,为什么不使用类语法呢?
SI.SpaceShip = function (options) { ...