Add call and apply methods to RegExp.prototype
Steven L.
steves_list at hotmail.com
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 (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)
_________________________________________________________________
i’m is proud to present Cause Effect, a series about real people making a difference.
http://im.live.com/Messenger/IM/MTV/?source=text_Cause_Effect
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.mozilla.org/pipermail/es-discuss/attachments/20071219/f9e1ef94/attachment-0002.html
More information about the Es4-discuss
mailing list