簡體   English   中英

在 function 內部調用 function 出現錯誤“未定義”

[英]Getting error “not defined” for function called inside 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()函數但發生錯誤,提示未定義 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;

並且發生此錯誤說:在此處輸入圖像描述

那么首先requestMovies是一個實例方法,它應該像this.requestMovies()那樣引用,其次,因為這是一個實例方法,它不能從 static 方法調用,因此方法searchMovie不能是 static 方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM