"Method group"-esque syntax in Javascript?
<p>C# has an awesome syntactical feature where, for a function expecting a delegate type, you can pass in a "method group", like so:</p>

<pre><code>"string".Count (Char.IsWhiteSpace);
</code></pre>

<p>rather than the (relatively speaking) noisy:</p>

<pre><code>"string".Count (c =&gt; Char.IsWhiteSpace (c));
</code></pre>

<p>(Edit: better example).</p>

<p>I'd like to do something similar in Javascript, which has far noisier syntax for anonymous functions:</p>

<pre><code>var name = "foobar".replace (/^\w/, function (c) { return c.toUpperCase (); });
</code></pre>

<p>I've played around with various attempts and permutations of the arguments to the functional form of <code>String.prototype.replace</code>, using the <code>call</code> and <code>apply</code>, but the string argument passed in (<code>c</code> in the above example) is apparently not <code>this</code> in the scope within <code>toUpperCase</code> (I'm ending up with a less-than-helpful <code>DOMWINDOWoobar</code> in the best of cases, and <code>TypeError</code> in the worst).</p>

<p>Obviously I can wrap the function like I had above and life can go on, but is there anyway to do something similar to method group application, or passing that function in so that it is properly invoked on the matched characters?</p>
