File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes differentiate btw field and method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "differentiate btw field and method" Watch "differentiate btw field and method" New topic

differentiate btw field and method

Ken Ng

Joined: Feb 14, 2004
Posts: 26
The for(var in obj) loop can enumerate most (if not all) properties of a given obj, but how to differentiate whixh are the fields and which are the methods. Are there predefined functions that can do that?

Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 413
Well, it depends on a browser. I tried your code in IE6 and firefox.

if you run the code you posted in IE, methods wil not be returned, but event handlers are. For them typeof(window.document[property]) will be "object" if they are not set and "function" if they are set. You can filter them out since they always start with "on".

In firefox, event handlers will not be returned, but methods are.
typeof(window.document[property]) will be "function" for those methods.
[ December 07, 2005: Message edited by: Yuriy Fuksenko ]
I agree. Here's the link:
subject: differentiate btw field and method
It's not a secret anymore!