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_______________________________________________
Es4-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es4-discuss