Add call and apply methods to RegExp.prototype

Steven L. steves_list at
Wed Dec 19 17:59:01 PST 2007

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 (, array[i], i, array))
    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)

i’m is proud to present Cause Effect, a series about real people making a difference.
-------------- next part --------------
An HTML attachment was scrubbed...

More information about the Es4-discuss mailing list