[Javascript] Terminating a nested function?
Paul Novitski
paul at novitskisoftware.com
Wed Apr 6 12:02:25 CDT 2005
At 05:12 PM 4/5/2005, Kimberly Batteau wrote:
>When in a function nested several layers deep, is there a way in JS to
>halt the execution without returning to all of the parent functions?
Kimberly,
I don't know of a way to do this in javascript (cf. ASP's Response.End).
However, even if you could do it, it's not really good structural
programming practice to abort like that. Much better to honor the natural
structures in the language and exit gracefully. That way you can ensure
that any parent process in mid-stream can close out properly.
For example, you can establish a coding convention in which a "bail out"
flag can be set by each subroutine and examined after each call:
var everythingsOK = true;
function Aardvark()
{
openDatabase();
if (everythingsOK)
{
doStuff;
}
closeDatabase();
}
function openDatabase()
{
everythingsOK = openConnection();
if (everythingsOK)
{
everythingsOK = doSomethingElse();
}
}
etc.
Paul
More information about the Javascript
mailing list