Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- Turning frequently used code into a function


lucy24 - 7:40 pm on Oct 9, 2012 (gmt 0)


Personally I like subfunctions, but that's coding style.

flag = checkIt(any necessary variables here)
if (flag == 1)
{ do your stuff}

where fn checkIt does something like

newflag = 0;
if (lastIndexOf blahblah etc) {newflag = 1}
if (lastIndexOf other blahblah etc) {newflag = 1}
etc
return newflag

With exact wording based on language.

Generally anything that happens the same way two or more times goes in a subroutine of some kind, unless it involves tossing around variables that are so huge it would slow down the whole thing. Well, that's a www universal isn't it? It's why CSS and Includes were invented ;)


Thread source:: http://www.webmasterworld.com/javascript/4505715.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com