Connecting Tech Pros Worldwide Help | Site Map

javascript 'function not defined' error in recursion

 
LinkBack Thread Tools Search this Thread
  #1  
Old June 21st, 2006, 10:10 AM
Newbie
 
Join Date: Jun 2006
Posts: 1
Default javascript 'function not defined' error in recursion

hi, i have a problem which recursion fits perfectly, however; after working with the base function (which has no errors and works correctly) the recursions return a "function not defined" error in ff's js console. i tried a few things that came to mind but nothing has changed it... i found some interesting articles on the net regarding javascript's callbacks, and found out that due to callbacks recursion may end up eating a lot more memory than normal recursion does, which makes it sound like js and recursion don't go together.

the second time i call value1(), when it is in the first loop of the recursive function, i get the 'function not defined' error. i also get a not defined error regarding the chars string on that same line if you get past the function error. i'm guessing its related...

any help is appreciated.

<script type="text/javascript">
var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ";

function value1(baseChar, base, options) {
this.baseChar = baseChar;
this.base = base;

if(options == "")
this.valid = new Array(0);
else {
this.valid = new Array(0);

for(var i=0; i<options.length; i++)
this.valid.push(options.substring(i,i+1));
}

this.child = new Array(0);
}

function mod() {
var aNum = 0;
var input = "\"eHgMYUn_MWW[SLZ!kKOiM\\SX[Uif'GcaO]YU`eWPJIv|g`YTVTlrUPQT`R_T MgIO~pcM[QHaQVrYI^u'f,ueHgMYU,";

var v1opt = new value1("", 0, chars);

recurse1(v1opt);
}

function recurse1(v1opt) {
document.write("base char: "+ v1opt.baseChar +"<br />");
document.write("base: "+ v1opt.base +"<br />");
document.write("valid: "+ v1opt.valid.join() +"<br />");

for(var i=0; i<v1opt.valid.length; i++) {
if((v1opt.base + v1opt.valid[i].charCodeAt(0)) <= 1286) {
document.write("child: "+ v1opt.valid[i].charAt(0) +"<br /><blockquote>");
var a = new value1("", 0, chars);
child = v1opt.child.push(a);

for(var j=0; j<chars.length; j++)
if((child.base + chars.charCodeAt(j)) <= 1286)
child.valid.push(chars.charAt(j));
}
}

if(v1opt.child.length != 0)
for(var i=0; i<v1opt.child.length; i++)
recurse1(v1opt.child(i));

document.write("</blockquote>");
}
Reply
  #2  
Old June 22nd, 2006, 01:45 PM
Newbie
 
Join Date: Jun 2006
Posts: 3
Default

May be th problem is in v1opt.child(i), as if the recursion is working correctly with scalar types. Have U tried to call the recurse1 for any scalar type?
You can assign this object to any variable and try to call for this one.
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.