• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

differentiate btw field and method

 
Ken Ng
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
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
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic