typeof /regexp/ returns 'object'

RESOLVED INVALID

Status

()

Core
JavaScript Engine
RESOLVED INVALID
9 years ago
9 years ago

People

(Reporter: Peter Kim, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

9 years ago
User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b3) Gecko/20090305 Firefox/3.1b3
Build Identifier: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b3) Gecko/20090305 Firefox/3.1b3

typeof /regexp/ returns 'object'

expected value = 'regexp'

example: typeof 123 returns 'number'
typeof 'hello' returns 'string'
typeof function(){} returns 'function'
typeof [1,2,3] returns 'array'

Similarly, typeof /regexp/ should return 'regexp' instead of 'object', unless typeof new RegExp() is used.

Reproducible: Always

Steps to Reproduce:
1. typeof /regexp/
Actual Results:  
returns 'object'

Expected Results:  
should return 'regexp'

In safari/webkit, 'function' is returned. This is obviously wrong, and I have reported it.

Comment 1

9 years ago
'object' would appear to be correct - see discussions in bug 61911

Comment 2

9 years ago
John, thanks for the link. John, please follow the discussion in bug 61911 for the background. -> invalid.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 9 years ago
Resolution: --- → INVALID
(In reply to comment #0)
> typeof [1,2,3] returns 'array'

Peter, do you see any browser-hosted or other JS implementation returning 'array' from typeof? That's non-standard (however nice an idea -- compatibility sucks). I am curious if anyone is trying it on for size.

/be
(Reporter)

Comment 4

9 years ago
my mistake... typeof [1,2,3] doesn't return 'array'. it returns 'object'.

when I need to check the type of an object, I usually create a function called type() in the object's prototype.

for example,

Array.prototype.type = function() {return 'Array';}
String.prototype.type = function() {return 'String';} 
Number.prototype.type = function() {return 'String';} 
etc...

then I can just do obj.type() to get the type.
(Reporter)

Comment 5

9 years ago
Omg, it's you sir, Brendan Eich!
You need to log in before you can comment on or make changes to this bug.