Connecting Tech Pros Worldwide Forums | Help | Site Map

Why (new RegExp) type is function not object

EME
Guest
 
Posts: n/a
#1: Dec 8 '07
typeof new RegExp
----------------------------------------------------
Why (new RegExp) type is function not object

very thanks for you consulation

RobG
Guest
 
Posts: n/a
#2: Dec 8 '07

re: Why (new RegExp) type is function not object


EME wrote:
Quote:
typeof new RegExp
----------------------------------------------------
Why (new RegExp) type is function not object
>
very thanks for you consulation
A function is an object. The ECMA spec section 11.4.3 says that the
typeof operator returns 'function' for objects that are functions[1],
and 'object' for objects that aren't functions.

Note that IE doesn't do that, it returns 'object' for functions.


1. It actually says "native and implements [[call]]", but it means
function. :-)


--
Rob
"We shall not cease from exploration, and the end of all our
exploring will be to arrive where we started and know the
place for the first time." -- T. S. Eliot
AKS
Guest
 
Posts: n/a
#3: Dec 8 '07

re: Why (new RegExp) type is function not object


On 8 ΔΕΛ, 06:33, EME <megaupload.sh...@gmail.comwrote:
Quote:
typeof new RegExp
----------------------------------------------------
Why (new RegExp) type is function not object
>
Actually, only SpiderMonkey creates function, evaluating -new RegExp-
expression. It's more like extension of the engine since the
calculated object has no properties length and prototype.

AKS
Guest
 
Posts: n/a
#4: Dec 8 '07

re: Why (new RegExp) type is function not object


On 8 ΔΕΛ, 09:03, RobG <rg...@iinet.net.auwrote:
Quote:
>
Note that IE doesn't do that, it returns 'object' for functions.
>
I hope you meant: "it returns 'object' for host functions".


EME
Guest
 
Posts: n/a
#5: Dec 8 '07

re: Why (new RegExp) type is function not object


for furthur more,i have detail test below:
typeof new RegExp //result 'function' in Firefox, 'object' in IE6
new RegExp instanceof Function //result false in Firefox

(new RegExp)() in Firefox is same as (new RegExp).exec()
David Mark
Guest
 
Posts: n/a
#6: Dec 8 '07

re: Why (new RegExp) type is function not object


On Dec 8, 12:30 am, AKS <aksus...@yandex.ruwrote:
Quote:
On 8 ΔΕΛ, 09:03, RobG <rg...@iinet.net.auwrote:
>
>
>
Quote:
Note that IE doesn't do that, it returns 'object' for functions.
>
I hope you meant: "it returns 'object' for host functions".
I would think so.
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#7: Dec 8 '07

re: Why (new RegExp) type is function not object


David Mark wrote:
Quote:
On Dec 8, 2:55 am, EME <megaupload.sh...@gmail.comwrote:
Quote:
>new RegExp instanceof Function //result false in Firefox
>
It isn't an instance of Function (it is an instance of RegExp.)
It isn't an instance of anything, as that would imply class-based inheritance.


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
David Mark
Guest
 
Posts: n/a
#8: Dec 8 '07

re: Why (new RegExp) type is function not object


On Dec 8, 8:57 am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
Quote:
David Mark wrote:
Quote:
On Dec 8, 2:55 am, EME <megaupload.sh...@gmail.comwrote:
Quote:
new RegExp instanceof Function //result false in Firefox
>
Quote:
It isn't an instance of Function (it is an instance of RegExp.)
>
It isn't an instance of anything, as that would imply class-based inheritance.
>
You are kidding right? The operator quoted above that sentence should
explain why I used that terminology.

Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#9: Dec 8 '07

re: Why (new RegExp) type is function not object


David Mark wrote:
Quote:
On Dec 8, 8:57 am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
Quote:
>David Mark wrote:
Quote:
>>On Dec 8, 2:55 am, EME <megaupload.sh...@gmail.comwrote:
>>>new RegExp instanceof Function //result false in Firefox
>>It isn't an instance of Function (it is an instance of RegExp.)
>It isn't an instance of anything, as that would imply class-based inheritance.
>
You are kidding right?
I am not.
Quote:
The operator quoted above that sentence should explain why I used that terminology.
The operator above was borrowed from Java, a programming language that
uses only class-based inheritance, to ease programming in JavaScript for
developers that a familiar with Java. However, `instanceof' is only a
name, not a hint regarding the underlying concept of the operation in
implementations of Edition 3 of the ECMAScript Language Specification.
It is therefore inappropriate to speak of objects as instances of their
constructors.

http://developer.mozilla.org/en/docs...of_Differences


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
David Mark
Guest
 
Posts: n/a
#10: Dec 8 '07

re: Why (new RegExp) type is function not object


On Dec 8, 9:15 am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
Quote:
David Mark wrote:
Quote:
On Dec 8, 8:57 am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
Quote:
David Mark wrote:
>On Dec 8, 2:55 am, EME <megaupload.sh...@gmail.comwrote:
>>new RegExp instanceof Function //result false in Firefox
>It isn't an instance of Function (it is an instance of RegExp.)
It isn't an instance of anything, as that would imply class-based inheritance.
>
Quote:
You are kidding right?
>
I am not.
That was a rhetorical question. I know you are serious about being
pedantic.
Quote:
>
Quote:
The operator quoted above that sentence should explain why I used that terminology.
>
The operator above was borrowed from Java, a programming language that
uses only class-based inheritance, to ease programming in JavaScript for
No kidding.
Quote:
developers that a familiar with Java. However, `instanceof' is only a
name, not a hint regarding the underlying concept of the operation in
I wasn't taking a hint from it.
Quote:
implementations of Edition 3 of the ECMAScript Language Specification.
It is therefore inappropriate to speak of objects as instances of their
constructors.
Thanks for that.
RobG
Guest
 
Posts: n/a
#11: Dec 8 '07

re: Why (new RegExp) type is function not object


On Dec 9, 1:06 am, David Mark <dmark.cins...@gmail.comwrote:
Quote:
On Dec 8, 9:15 am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
[...]
Quote:
Quote:
It is therefore inappropriate to speak of objects as instances of their
constructors.
>
Thanks for that.
Maybe the instanceof operator should be "constructedby"? :-)


--
Rob
John G Harris
Guest
 
Posts: n/a
#12: Dec 8 '07

re: Why (new RegExp) type is function not object


On Sat, 8 Dec 2007 at 14:57:13, in comp.lang.javascript, Thomas
'PointedEars' Lahn wrote:
Quote:
>David Mark wrote:
Quote:
>On Dec 8, 2:55 am, EME <megaupload.sh...@gmail.comwrote:
Quote:
>>new RegExp instanceof Function //result false in Firefox
>>
>It isn't an instance of Function (it is an instance of RegExp.)
>
>It isn't an instance of anything, as that would imply class-based inheritance.
Let's be really pedantic now. "An instance of RegExp" is just short for

"The object is a member of the class of all those objects that could
possibly be constructed by the function named RegExp".


Let's be differently pedantic now. Here is a quote from the ECMAScript
standard :

"RegExp instances inherit properties" ...


John
--
John Harris
Richard Cornford
Guest
 
Posts: n/a
#13: Dec 12 '07

re: Why (new RegExp) type is function not object


RobG wrote:
Quote:
On Dec 9, 1:06 am, David Mark wrote:
Quote:
>On Dec 8, 9:15 am, Thomas 'PointedEars' Lahn wrote:
[...]
Quote:
Quote:
>>It is therefore inappropriate to speak of objects as
>>instances of their constructors.
>>
>Thanks for that.
>
Maybe the instanceof operator should be "constructedby"? :-)
The - instanceof - operator makes an assertion about the runtime
relationship between the objects on an object's prototype chain and the
object/value referred to by the - prototype - property of a function at
the moment of the operation. Because the - prototype - properties of
functions can be assigned values at any time the results of -
instanceof - do not necessarily represent anything beyond the outcome of
the pertinent algorithms.

As usual, if the 'Class' concept has been employed in javascript code
design, not violated at runtime, and no attempt has been made to extend
that concept across possible multiple frames (so there is only a single
instance of each 'constructor') then javascript's - instanceof - can be
employed as if it was broadly analogous to Java's - instanceof -.
Unfortunately the coincidence of names tends to give people familiar
with Java the false impression that the two operators are more related
than they actually are (and then they whinge when they find out that the
relationship in javascript is much more specific and concrete than the
conceptual relationship that is implied in Java).

Richard.

Closed Thread