Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Function instanceof Object and vice-versa ?

Reply
Thread Tools

Function instanceof Object and vice-versa ?

 
 
System Administrator
Guest
Posts: n/a
 
      03-10-2007
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
 
Reply With Quote
 
 
 
 
VK
Guest
Posts: n/a
 
      03-10-2007
On Mar 10, 11:07 pm, System Administrator
<(E-Mail Removed)> wrote:
> 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.

 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      03-10-2007
On Mar 11, 6:07 am, System Administrator
<(E-Mail Removed)> wrote:
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check if object is an instanceof a class, but not a sub-class? laredotornado Java 47 06-29-2010 07:05 AM
Need help, get error "Object does not match target type" in one instanceof an app, when others work Lasse Vågsæther Karlsen ASP .Net 1 11-27-2007 02:46 PM
Which is better (in Java), depending on instanceof a lot, or having my own getType function PaulSchrum Java 4 01-23-2007 10:14 AM
instanceof NOT (always) bad? The instanceof myth. dmx_dawg@hotmail.com Java 21 07-20-2006 07:06 PM
Quick question on polymorphism and instanceof WillieLWZ Java 8 02-23-2006 06:56 AM



Advertisments