Add call and apply methods to RegExp.prototype
Yuh-Ruey Chen
maian330 at gmail.com
Sun Dec 23 00:51:58 PST 2007
Brendan Eich wrote:
> On Dec 21, 2007, at 7:33 AM, StevenLevithan wrote:
>
> > Yes, its easy to pull off oneself, so I don't care much other way.
> > Still, it
> > seems pretty weird to me to be able to do ``regex(str)`` but not
> > ``regex.call(context, str)``. This is accentuated when typeof returns
> > "function" for regexes (though it seems ES4 will change this to
> > "object").
>
> Hey Steve, Yuh-Ruey (I owe both of you replies to the list, for Steve
> agreeing about ES3 capturing paren broken design, Yuh-Ruey on fine
> points about instanceof, etc. -- I wanted to drop a note here,
> quickly, and catch up next week while I'm off).
>
I'm glad you still remember it :)
> This raises the question: since there is only one argument to exec or
> test, so why do you ever need to delegate invocation using apply or
> call? The only case that comes to mind is a generic programming use-
> case where you might have either a function object or a regexp and
> you want to .apply it with an argument array. But again, you could
> just invoke foo(arg) given foo denoted either a function or a regexp.
> True, the most generic program would not want to hardwire argument
> count, so would want .apply. But still, the motivation for call and
> apply in RegExp.prototype seems weak.
With currying, I find that use case a moot point. For example, we could do:
foo(regex.exec.bind())
and foo would still be generic. So really, regex invocation is not
needed. Speaking of bind (or whatever it's called), I hope the function
is memoized, since it might be used a lot.
More information about the Es4-discuss
mailing list