如何解决创建课程以获取天气
请帮忙,我创建了主类来获取四天的天气,但是控制台抛出错误-未定义getCoordinates。问题是什么?还是函数初始化错误?我具有函数getCoordinates,而不是获取城市并返回纬度和经度,然后应将其传递给函数get WeatherForeCast以获取天气,并从该函数将数据传递到函数renderForeCastInfo中以获取四天的天气。怎么了?
set('spark.scheduler.mode','FAIR')
解决方法
对于成员函数,您必须参考this
。请参见下面的代码。
class Weather {
constructor(city) {
this.city = city
}
async getCoordinates(city) {
//code
}
async getWeatherForecast(locationCoordinates) {
//code
}
fahrenheitToCelsius(temp) {
//code
}
renderForecastInfo(currently,daily) {
//code
}
init() {
this.getCoordinates().then(coords => {
return this.getWeatherForecast(coords);
}).then((forecast) => {
const { currently,daily } = forecast;
this.renderForecastInfo(currently,daily);
});
}
}
const w1= new Weather();
w1.init();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。