Wrapping a JavaScript callback redefining "this"
<p>I know about <code>call</code> and <code>apply</code> in JavaScript, but I'm currently stuck with the following scenario.</p>

<p>I'm using <strong>Benchmarkjs</strong>, and it has an API defined like this:</p>

<pre><code>.on(eventType, listener)
</code></pre>

<p>So I'd do, for instance:</p>

<pre><code>/* Register the onStart callback */
suite.on('start', onStart);
</code></pre>

<p>My <code>onStart</code> function will be called so that <code>this === suite</code>.</p>

<p>How can I do so that I can define one of the <code>arguments</code> of <code>onStart</code>?</p>

<p>My code is something like this:</p>

<pre><code>foo = function() {
   this.suite.on('start', this.onStart);
}
</code></pre>

<p>I'd like my <code>onStart</code> function to have a reference to <code>foo</code>.</p>

<p>Any suggestions?</p>
