Add call and apply methods to RegExp.prototype
Yuh-Ruey Chen
maian330 at gmail.com
Fri Dec 21 00:15:46 PST 2007
Sounds like a good idea to me. On the other hand, this can already
easily be done in ES3.
Steven L. wrote:
> ES4 proposals include making regexes callable as a function on a
> single string argument, which serves as a shorthand for calling the
> regex's exec method. To further extend this idea, what about also
> including call and apply methods on RegExp.prototype, so that regexes
> can more easily be used with functional programming? For e.g., if one
> were to model a "where" function after JS 1.6's Array.prototype.filter
> like so:
>
> function where (array, func, context) {
> var results = [];
> for (var i = 0; i < array.length; i++) {
> if (func.call(context, array[i], i, array))
> results.push(array[i]);
> }
> return results;
> }
>
> ...They could then use, e.g., where(["ab", "ba", "a", "b"], /^a/) to
> return all array elements starting with the letter "a" (["ab", "a"]).
>
> Thoughts? Is this possibly already included in the proposals? (sorry
> if I missed it)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.mozilla.org/pipermail/es-discuss/attachments/20071221/b9498e85/attachment-0002.html
More information about the Es4-discuss
mailing list