[英]Getting error “not defined” for function called inside function
I have a class and in that class, it has two functions and one static function.我有一个 class 和 class,它有两个功能和一个 static ZC1C425268E68385D1AB4Z15074。 In the first function called
requestMovie()
I want to fetch data from API, then the second function is used to generate the URL called generateUrl()
, and in the third function called searchMovie()
I want to call the generateUrl()
and requestMovie()
functions but an error occurs that says the function is not defined In the first function called
requestMovie()
I want to fetch data from API, then the second function is used to generate the URL called generateUrl()
, and in the third function called searchMovie()
I want to call the generateUrl()
and requestMovie()
函数但发生错误,提示未定义 function
const MOVIE_ENDPOINT = 'https://api.themoviedb.org/3/';
const API_KEY = '####';
class ApiTransactions {
requestMovies(url, onComplete, onError){
return fetch(url)
.then((response) => response.json())
.then(onComplete)
.catch(onError);
}
generateUrl(path){
const url = `${MOVIE_ENDPOINT}${path}?api_key=${API_KEY}`;
return url;
}
static searchMovie(keyword){
const url = generateUrl('search/movie') + '&query=' + keyword;
requestMovies(url,renderResult, fallbackResult);
}
}
export default ApiTransactions;
and this error occurs saying: enter image description here并且发生此错误说:在此处输入图像描述
Well first of all requestMovies
is an instance method and it should be referenced like this.requestMovies()
, second since this is an instance method it can not be called from a static method, and so the method searchMovie
can not be a static method.那么首先
requestMovies
是一个实例方法,它应该像this.requestMovies()
那样引用,其次,因为这是一个实例方法,它不能从 static 方法调用,因此方法searchMovie
不能是 static 方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.