Add call and apply methods to RegExp.prototype

Steve steves_list at
Fri Dec 21 19:58:26 PST 2007

(I agree with liorean.)

> 1. Is regexp callability worth adding in ES4?

IMO, no it isn't. Although I do enjoy the convenience of things like 
array.filter(/regex/) (which works in Firefox today), outside of array 
iteration methods it typically just saves five characters and is not 
behavior most people would expect. If I want to be able to pass regexes 
around as functions and use call and apply on them in the cases where it is 
helpful, I can implement this functionality myself (my custom methods would 
likely ignore the context argument ... e.g.,str){return this.exec(str);}; ).

> 2. If yes to 1, do we really need .call and .apply?

I don't think it's needed, but the symmetry with real functions seems 
natural to me (but only if callability were to be preserved, which as noted 
above is not something I'd argue for).

As for whether test or exec should be the method used if callability is 
preserved, I think test is what would be desired in far more cases. However, 
I have grown used to the idea of exec being the default method (since the 
functionality of all regex and regex-using string methods can be reproduced 
using exec), and the null and array values returned by exec cast nicely to 
booleans anyway. So, I don't really care either way.

More information about the Es4-discuss mailing list