Kirn Khaira wrote:
I have a flowscript function that takes in start and end parameters and
creates a form that includes a previous and next button on the form
page. After the form has been submitted, with either a next submit call
or previous submit call, it calls itself with new values for the start
and end parameters. Basically the function looks like this:
function myForm(start, end)
{
// get a record list from an hsql query using the start and
end values
var model = pu.processToDOM(…);
var form = new Form(model.getDocumentElement());
// set the start and end form variables…
form.showForm(…);
// after submit do some calculations on the start and end
values and call this function again
myForm(newStart,newEnd);
}
My question is, is this the best way to do this? Is this too memory
intensive?
The Rhino JavaScript interpreter does tail call optimization, so there's
nothing inherently memory-wasting about recursively calling the function
if the recursive call is the last thing in the function.
But, your example will create a whole new Form object instance for each
iteration, which may not be what you want, and will suck up memory each
time through.
Typically I just use a while-loop when I want to display the same form
again and again, using the same Form instance...
function myForm()
{
// default start and end values:
var start = 0;
var end = 25;
var form = new Form(...);
var finished = false;
while(!finished) {
form.showForm(...);
// set new start and end as appropriate
start = ...;
end = ...;
if(...) finished = true; //exit condition
}
//show confirmation screen or whatever
}
Hope that helps
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]