我想通过一个对象的路径

时间:2018-09-28 21:44:06

标签: javascript if-statement

我想将带有函数的路径传递给构造函数

this.elementImg.src = `${this.changeImage()}`;  

为什么这不起作用

changeImage = () => {
    if (this.speed < 6) {
        this.imagePaths[0];
    } else if (this.speed >= 6 && this.speed < 9) {
        this.imagePaths[1];
    } else if (this.speed >= 9) {
        this.imagePaths[2];
    }
}

1 个答案:

答案 0 :(得分:1)

该函数需要return条语句。

此外,您不需要进行>=测试,因为先前的<测试可确保该值将是该值的>=或将不会用于{{1 }}。

else