简体   繁体   English

在 function 内部调用 function 出现错误“未定义”

[英]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.

相关问题 在类内部定义的函数上获得参考错误“ ReferenceError:insertLevelOrder未定义” - Getting a reference error “ReferenceError: insertLevelOrder is not defined” on function defined inside a class jQuery函数未在Ajax函数内部被调用 - jquery function not getting called inside of an ajax function 函数内部未定义URLSearchParams错误 - URLSearchParams not defined error Inside A Function li元素内的范围函数未被调用 - scope function inside li element is not getting called 如果没有调用条件,则 javascript 中的函数 - A function inside javascript if condition is not getting called JavaScript中的Ajax函数没有被调用 - Ajax function inside JavaScript is not getting called 有一个updateTotal()未定义的错误。 updateTotal()函数似乎已正确定义和调用。 为什么会出现此错误? - Got an updateTotal() not defined error. updateTotal() Function seems to be defined and called appropriately. Why would I be getting this error? 在angularjs控制器中定义的函数的函数未定义错误 - Function not defined error for a function that's defined inside an angularjs controller 调用javascript函数时出错:ReferenceError: <function name> 没有定义 - Error when javascript function is called: ReferenceError: <function name> is not defined 为什么不能通过在promise中调用的函数内部的闭包来定义解析? - Why is resolve not defined through closure inside a function called in a promise?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM