473,320 Members | 2,092 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,320 software developers and data experts.

Function instanceof Object and vice-versa ?

Hi:

Can someone explain why BOTH of the following are true ?

Function instanceof Object //true
Object instanceof Function //true
(Either one or the other should be true, not both, right ?)

Best regards,
--j
Mar 10 '07 #1
2 2153
VK
On Mar 10, 11:07 pm, System Administrator
<f.dhjkafjkl...@fjk.dsfjkds.comwrote:
Hi:

Can someone explain why BOTH of the following are true ?

Function instanceof Object //true
Object instanceof Function //true

(Either one or the other should be true, not both, right ?)
Wrong. This is prototype based language here, not a class based.
a instanceof b
check is a "syntax beautifying" for
b.prototype.isPrototypeOf(a)
While "making JavaScript out of LiveScript" one of requests to Brendan
Eich was to make the syntax closer to Java - because Java was cool
everything else lame :-) at that time.

Now analyze the result with the actual meaning of instanceof in
javascript in mind. Overall until
http://blogs.msdn.com/ericlippert/ar.../06/53352.aspx
is fully read and understood you will keep getting a lot "puzzles"
like that one.

Mar 10 '07 #2
On Mar 11, 6:07 am, System Administrator
<f.dhjkafjkl...@fjk.dsfjkds.comwrote:
Hi:

Can someone explain why BOTH of the following are true ?

Function instanceof Object //true
Object instanceof Function //true
Function and Object are both constructors, and therefore functions.
And all functions are also objects.
So:

function x(){};
x instance of Object // true
x instance of Function // true

y = {};
y instanceof Object // true
y instanceof Function // false

--
Rob

Mar 11 '07 #3

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

Similar topics

7
by: chirs | last post by:
Hi, These 2 lines caused an error in IE5. The error is "Function expected". Why? var d=new Date(); document.write(d instanceof Object + "<br>"); Thanks.
6
by: Alexis Nikichine | last post by:
Hello, Today, I have a function: function f() { } and am looking for a way of distinguishing, from inside f, whether it
41
by: Telmo Costa | last post by:
Hi. I have the following code: -------------------------------------- function Tunnel() { //arguments(???); } function Sum() { var sum = 0; for (i=0; i<arguments.length; i++) sum +=...
17
by: Matt Kruse | last post by:
Perl's map() function is a powerful shortcut to accomplish many "loop over an array and do X" operations. Below is a quick hack to simulate similar functionality. I've used it a few times and find...
32
by: David Mark | last post by:
I've got a collection of functions that accept a function or object (paired with a method name) as a callback. For the longest time I have relied on this test. (typeof cb == 'function') ...
12
by: EME | last post by:
typeof new RegExp ---------------------------------------------------- Why (new RegExp) type is function not object very thanks for you consulation
13
by: Robert | last post by:
Hi, Is it possible to intercept a call to "instanceof" and return something different? I wanted to see if it was possible to implement something like multiple inheritance, especially to use...
30
by: kj | last post by:
My book (Flanagan's JavaScript: The Definitive Guide, 5th ed.) implies on page 111 that the following two constructs are equivalent: ( x.constructor == Foo ) and ( x instanceof Foo ) The...
18
by: Aaron Gray | last post by:
I know this has probably been argued to death, but I am going to raise it fresh again, and basically lets have an unofficial 'isArray()' contest that we can hopefully put it to rest as best as we...
7
by: Andrew Poulos | last post by:
Say I have this foo = function() { // blah }; bar = fuction(fnName) { /* If fnName equalled "foo" * How do I test that foo, as a function, * exists and then, if it exists, call it?
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.