473,385 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Why (new RegExp) type is function not object

EME
typeof new RegExp
----------------------------------------------------
Why (new RegExp) type is function not object

very thanks for you consulation
Dec 8 '07 #1
12 2029
EME wrote:
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
Dec 8 '07 #2
AKS
On 8 ΔΕΛ, 06:33, EME <megaupload.sh...@gmail.comwrote:
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.

Dec 8 '07 #3
AKS
On 8 ΔΕΛ, 09:03, RobG <rg...@iinet.net.auwrote:
>
Note that IE doesn't do that, it returns 'object' for functions.
I hope you meant: "it returns 'object' for host functions".
Dec 8 '07 #4
EME
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()
Dec 8 '07 #5
On Dec 8, 12:30 am, AKS <aksus...@yandex.ruwrote:
On 8 ΔΕΛ, 09:03, RobG <rg...@iinet.net.auwrote:
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.
Dec 8 '07 #6
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.
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Dec 8 '07 #7
On Dec 8, 8:57 am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
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.
You are kidding right? The operator quoted above that sentence should
explain why I used that terminology.

Dec 8 '07 #8
David Mark wrote:
On Dec 8, 8:57 am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
>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.

You are kidding right?
I am not.
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
Dec 8 '07 #9
On Dec 8, 9:15 am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
David Mark wrote:
On Dec 8, 8:57 am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
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.
You are kidding right?

I am not.
That was a rhetorical question. I know you are serious about being
pedantic.
>
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.
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.
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.
Dec 8 '07 #10
On Dec 9, 1:06 am, David Mark <dmark.cins...@gmail.comwrote:
On Dec 8, 9:15 am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
[...]
It is therefore inappropriate to speak of objects as instances of their
constructors.

Thanks for that.
Maybe the instanceof operator should be "constructedby"? :-)
--
Rob
Dec 8 '07 #11
On Sat, 8 Dec 2007 at 14:57:13, in comp.lang.javascript, Thomas
'PointedEars' Lahn wrote:
>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.
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
Dec 8 '07 #12
RobG wrote:
On Dec 9, 1:06 am, David Mark wrote:
>On Dec 8, 9:15 am, Thomas 'PointedEars' Lahn wrote:
[...]
>>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.

Dec 12 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one...
0
by: Chris Croughton | last post by:
I'm trying to use the EXSLT regexp package from http://www.exslt.org/regexp/functions/match/index.html (specifically the match function) with the libxml xltproc (which supports EXSLT), but...
4
by: mike.biang | last post by:
I have an ASP page that is using an XMLHTTP object to request various pages from my server. I keep a single session throughout the XMLHTTP requests by bassing the ASPSESSIONID cookie through the...
8
by: pamelafluente | last post by:
Hi guys, Is it possible to add "onload" (via Javascript) a new class to the <styleheader section? If yes, how would that be done ? <style type="text/css" media="screen"> .NewStyleClass{...
11
by: HopfZ | last post by:
I coudn't understand some behavior of RegExp.test function. Example html code: ---------------- <html><head></head><body><script type="text/javascript"> var r = /^https?:\/\//g;...
6
by: runsun pan | last post by:
Hi I am wondering why I couldn't get what I want in the following 3 cases of re: (A) var p=/(+-?+):(+)/g p.exec("style='font-size:12'") -- // expected
2
by: Uldis Bojars | last post by:
Hi All, I have encountered problems with JS RegExp.exec() and can't find what is the problem. Could you help me? formRequest is a function that extracts some information from XMLHTTPRequest...
10
by: pamelafluente | last post by:
Hi, this time I am trying to add a style on the fly.I wish equivalency with this one (only the menuItemStyle line): <head> <style type="text/css" media="screen"> ... some static styles ......
11
by: Daniel Norden | last post by:
Hi. Is it necessary to use the 'new' operator for built-in types like String, Number, RegExp, .....? The result seems to be the same with or without 'new'. For example in a line that looks...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.