默认情况下,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;
}
答案 0 :(得分:2)
您可以使用粗箭头功能:
function methodA(link,title){
return superagent.get(link)
.then(page => page.text)
.then(text => methodB(text, title));
}