Thursday, August 16, 2012

javaScript: Nested Functions

Another Intresting concept that poped up in JavaScript
:nested functions inside of other functions : This provides a way to make a function private. If you want these be accessable there must be a accessor method in the outfunction otherwise they will be unreachable outside of the outter function

Here is an Example of what this looks like.

<!DOCTYPE html>
    <title>Nested Functions</title>
    <script type="text/javascript">
          function initiateMadness() {
            var sparta = {
                name : "Sparta"
            function madness() {
                alert("THIS. IS. " + + ".");
            document.onclick = makeAMessenger(madness, sparta);
//access the content of the inner function
   function makeAMessenger(func, context)
<script type="text/javascript">
<h1> Heading 1 </h1>
<p> THis is my program </p>

No comments:

Post a Comment