...

View Full Version : How to determine if a object contains a method?



EdwardKing
12-17-2007, 09:24 AM
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

Arty Effem
12-17-2007, 03:46 PM
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.

Trinithis
12-17-2007, 04:50 PM
if(o[x] instanceof Function)
o[x]();



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum