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>
<html>
<head>
<title>Nested Functions</title>
<script type="text/javascript">
function initiateMadness() {
var sparta = {
name : "Sparta"
};
function madness() {
alert("THIS. IS. " + this.name.toUpperCase() + ".");
}
document.onclick = makeAMessenger(madness, sparta);
}
//access the content of the inner function
function makeAMessenger(func, context)
{
window.name = context.name;
func();
}
initiateMadness();
</script>
</head>
<body>
<script type="text/javascript">
</script>
<h1> Heading 1 </h1>
<p> THis is my program </p>
</body>
</html>
I started this blog as a personal notepad, but it seems I'm getting more and more hits. Since people are reading this I starting sharing anything that I find interesting or usfull. I'm currently dedicating my time to expanding my knowledge into the more modern languages and ideas. If you find this information useful or a waste of your tome let me know by leaving commits or using the google +1 function at the bottom of the post. Thanks for viewing Daniel Haro
Showing posts with label Functions within functions. Show all posts
Showing posts with label Functions within functions. Show all posts
Thursday, August 16, 2012
Subscribe to:
Posts (Atom)