Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-17-2007, 09:24 AM   PM User | #1
EdwardKing
New Coder

 
Join Date: Jun 2005
Posts: 42
Thanks: 2
Thanked 0 Times in 0 Posts
EdwardKing is an unknown quantity at this point
How to determine if a object contains a method?

I have a object,and it contains some method,like follows:
node object has getSelected(),hasChildren() and getChildren() method,then I want to show its all child,I use recursion:
function showAllNode(node){
if(node.getSelected().hasChildren()){
var obj1=node1.getSelected().getChildren();
for(i=0;i<obj1.length;i++){
showAllNode(obj1[i]);
}
}
else{
alert(node1.getText());
}
}

when I execute above code,I find the recursion can execute first time and second time well,but when it recursion the third time,it raise javascript error,it say "object don't support this method or method" at the line " if(node.getSelected().hasChildren())".
My question how to determine a object method is validate?

Thanks
EdwardKing is offline   Reply With Quote
Old 12-17-2007, 03:46 PM   PM User | #2
Arty Effem
Banned

 
Join Date: May 2006
Location: England
Posts: 664
Thanks: 0
Thanked 84 Times in 84 Posts
Arty Effem can only hope to improve
Quote:
Originally Posted by EdwardKing View Post
function showAllNode(node){
if(node.getSelected().hasChildren()){
var obj1=node1.getSelected().getChildren();
for(i=0;i<obj1.length;i++){
showAllNode(obj1[i]);
}
}
else{
alert(node1.getText());
}
}
First try declaring i as a local variable and see if it makes any difference.
Arty Effem is offline   Reply With Quote
Old 12-17-2007, 04:50 PM   PM User | #3
Trinithis
Regular Coder

 
Join Date: Jun 2007
Location: USA
Posts: 527
Thanks: 26
Thanked 74 Times in 72 Posts
Trinithis will become famous soon enough
Code:
if(o[x] instanceof Function)
  o[x]();
Trinithis is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 03:38 PM.


Advertisement
Log in to turn off these ads.