gpt4 book ai didi

javascript - 我想传递一个对象的路径

转载 作者:行者123 更新时间:2023-12-03 01:02:36 24 4
gpt4 key购买 nike

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

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

最佳答案

该功能需要return声明。

此外,您不需要 >=测试,自上次 <测试确保该值为 >=该值,否则不会到达 else .

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

关于javascript - 我想传递一个对象的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52562983/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com