How to make cheerio's `$` accessible in helper functions in a clean way?
问题 I am fairly new to JavaScript and I am trying to refactor this const rp = require('request-promise'); const cheerio = require('cheerio'); // Basically jQuery for node.js // shared function function getPage(url) { const options = { uri: url, transform: function(body) { return cheerio.load(body); } }; return rp(options); } getPage('https://friendspage.org').then($ => { // Processing 1 const nxtPage = $("a[data-url$='nxtPageId']").attr('data'); return getPage(nxtPage).then($ => { // Processing 2