在同一类中的另一个功能中调用类功能
我正在尝试在JavaScript中执行某些操作,其中我在其他功能中调用返回功能,全部在类中,它是这样的:
class MyClass {
constructor (x,y) {
this.x = x;
this.y = y;
}
newValues () {
this.x = findNextXValue(this.x);
}
findNextXValue (x) {
let changeVal = x + 5;
return changeVal;
}
}
当我在P5J中尝试此代码时,我会发现一个错误,说FindNextXvalue未定义。我为什么不能这样做?任何澄清都将不胜感激,谢谢。
I'm trying to do something in Javascript where I call a return function inside of another function, all within a class, it goes something like this:
class MyClass {
constructor (x,y) {
this.x = x;
this.y = y;
}
newValues () {
this.x = findNextXValue(this.x);
}
findNextXValue (x) {
let changeVal = x + 5;
return changeVal;
}
}
When I try this code in p5js I get an error saying that findNextXValue is not defined. Why can't I do something like this? Any clarification would be appreciated, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
缺少这一点应该是...
但是您真的不需要通过此.x。只需在功能中访问this.x即可。
Missing this should be...
But you really don't need to pass this.x either. Just access this.x in the function.