然后在Javascript中将函数参数传递给

时间:2019-05-29 17:05:12

标签: javascript

默认情况下,methodB带有text参数。如何将title参数作为方法A的附加参数传递给方法B?

function methodA(link,title){
    return superagent.get(link).then(page => page.text).then(methodB); <== here
}

function methodB(text,title) {
    const promotions = [];
    const html = cheerio.load(text);

    html("#promolain > li > a > img").each((index, element) => {
        //console.log("scraping promo : "+element.attribs.title);
        promotions.push(element.attribs);
    });

    return promotions;
}

1 个答案:

答案 0 :(得分:2)

您可以使用粗箭头功能:

function methodA(link,title){
    return superagent.get(link)
        .then(page => page.text)
        .then(text => methodB(text, title));
}