Callable RegExp vs. typeof (was: Re: Draft of Function.prototype.bind.)

Brendan Eich brendan at mozilla.com
Thu Aug 13 10:07:36 PDT 2009


On Nov 4, 2008, at 10:43 AM, David-Sarah Hopwood wrote:

> The bug that Brendan and I were referring to was 61911:
> <https://bugzilla.mozilla.org/show_bug.cgi?id=61911>
>

For reference so new readers don't have to look far back in the old  
thread.


>> On FF3.0.3, a bit of testing reveals that RegExp instances are indeed
>> callable as functions, which presumably means they have an internal  
>> [[Call]]
>> property. And they are clearly native objects, not host objects.  
>> However,
>> unlike Rhino or WebKit, of FF3.0.3 at least, typeof of a RegExp  
>> does return
>> "object". I don't see any way to rationalize this as conforming to  
>> the spec.
>
> I agree; that's the same reasoning I was using.

Agreed, still.


> Note that in the comments of bug 61911, Brendan used the argument that
> regexp objects were proposed to be callable in ES4, but that is  
> presumably
> back up for discussion in Harmony. I would recommend against it:

Still agreed ;-).


> callable
> regexps were a SpiderMonkey extension never adopted by any non-Mozilla
> JavaScript implementation AFAIK, and they introduce an irregularity in
> the language.

Not so. See https://bugs.webkit.org/show_bug.cgi?id=28117 in  
particular https://bugs.webkit.org/show_bug.cgi?id=28117#c12 (quoting  
Luke Smith's words here):

"I found that /a/("abc") is implemented (inconsistently) in Firefox  
3.0, Firefox 3.5, Safari 3.2.1, Safari 4, Opera 9.6.3, Opera 10 beta2,  
Chrome 3 beta, and the WebKit nightlies. It is not implemented in IE6,  
IE7, IE8, or Chrome 2."

My comment at https://bugs.webkit.org/show_bug.cgi?id=28117#c21 opines  
that we may find it hard to remove callability, but it's even harder  
to make typeof /a/ return "function".

This is an issue still.

/be


More information about the es-discuss mailing list