Function instanceof Object and vice-versa ?

  • Thread starter System Administrator
  • Start date
S

System Administrator

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
 
V

VK

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/archive/2003/11/06/53352.aspx
is fully read and understood you will keep getting a lot "puzzles"
like that one.
 
R

RobG

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top