views:

92

answers:

1

In javascript on a browser, I can do this to see if an object is DOM-related:

obj instanceof Node

How do I accomplish this with google desktop? Node is undefined, and this doesn't work either:

obj instanceof basicElement
+1  A: 

I'm not a Google Desktop expert, I just had a little time on my hands! From the documentation basicElement itself is never instantiated; it just provides a set of common properties and events for its descendant UI objects.

Therefore it looks like a JavaScript object will never be an instanceof basicElement.

However, you can always check to see if the JavaScript object implements one of basicElements more obscure method or property names - this should give you a reasonable indication that the object you are working with is a basicElement. Using something like this:

if((obj != 'undefined') && (obj != null) && ("hitTest" in obj)){
    alert('Probably implements basicElement');
} else {
    alert('Not a basicElement');
}
Mark McLaren
What about something being an instance of the View class, for example?
Claudiu
I have had a quick look through the GD sample code and the only GD class that I found that you could directly instantiate is something called "DetailsView" and this is used for XML stuff. My guess is that this means instanceof is a bit of a dead end for determining a specified object's type. You would need to do something like ("obj instanceof (new ViewDetails())") for instanceof to work. Therefore, I think for most GD classes you would need to look for the existence of known properties/methods to determine an object's identification.
Mark McLaren