title: Is there a way to avoid having to pass both $ and $foo when using .each() inside a function?
body: <p>I am using cheerio to do some web scraping. There is a scenario that I want to get a table from a web page, and extract certain info I need.</p>
  
  <p>For example</p>
  
  <pre><code>const $table = $("table").eq(3);
  </code></pre>
  
  <p>Now I have a <code>$table</code> cheerio object. Since I'll use the table's data several times, I want to turn it into something simpler. I have defined something like this</p>
  
  <pre><code>// a row of the table
  function PlayDataEntry(no, title, bmsid, clear, ranking) {
      this.no = no;
      this.title = title;
      this.bmsid = bmsid;
      this.clear = clear;
      this.ranking = ranking;
  }
  </code></pre>
  
  <p>I would like to turn <code>$table</code> into an array of <code>PlayDataEntry</code>.</p>
  
  <p>So now I need to do some traversing:</p>
  
  <pre><code>PlayDataEntry.createFromTable = function($, $table) {
      const $rows = $table.find("tr")
                          .not(":has('th')"); // no header row
      const entries = [];
      $rows.each((i, el) =&gt; {
          const $row = $(el);
          const entry = PlayDataEntry.createFromRow($row);
          entries.push(entry);
      });
      return entries;
  };
  </code></pre>
  
  <p>And I'll use it like this</p>
  
  <pre><code>// ... some requests ...
  .then(($) =&gt; {
      const $table = MyList.getPlayDataTable($);
      const entries = PlayDataEntry.createFromTable($, $table);
      entries.forEach((entry) =&gt; {
          console.log(entry.toString());
      });
  })
  </code></pre>
  
  <p>But I feel having to pass <code>$, $table</code> is very awkward. The only reason I have to is because cheerio's <code>each()</code> gives me a bare element so I have to use $() again. I can make another method that directly receives a $ and returns an array of <code>PlayDataEntry</code>, but before that I would like to know is there other ways to avoid <code>$, $table</code>?</p>