Scripter Javascript Tutorial
javascriptmusiclogicscripterbookexcerpttutorial91Using Functions For Out of Scope Code
There are times when code is written as one long monolithic process,
or when there are enough conditional and loop statements being indented
where understanding what is happening in a particular code block gets
hard to keep track of. Oftentimes, this means that the code’s intent, or
scope, has gone a step too far from the original intent. In these cases,
code blocks which serve a particular purpose should be placed into their
own named function to make readability easier. As in the previous
newBar()
function example, the context for that purpose can
be provided by the function’s name and the arguments passed into it.