Ketan Jetty
enthusiasm for technology


A closure is formed by returning a reference to a function (inner function) that was created within an execution context of another function.

Closure example
<script type="text/javascript">
	function myClosure(arg1, arg2){
		var myLocalVar = 3;
		function innerFn(innerArg){
			return arg1 + arg2 + myLocalVar + innerArg;
		//return a reference to the inner function defined as - innerFn
		return innerFn;
	function runMe() {
		var myGlobalVar1 = myClosure(1, 2);
		alert("creating myClosure(1, 2)");
		alert(myGlobalVar1(4));		//returns 10 (1+2+3+4)
		alert(myGlobalVar1(5));		//returns 11 (1+2+3+5)
		alert(myGlobalVar1(6));		//returns 12 (1+2+3+6)
		var myGlobalVar2 = myClosure(11, 22);
		alert("creating myClosure(11, 22)");
		alert(myGlobalVar2(4));		//returns 40 (11+22+3+4)
		alert(myGlobalVar2(5));		//returns 41 (11+22+3+5)
		alert(myGlobalVar2(6));		//returns 42 (11+22+3+6)


CF Quick Reference

Ginger CMS
the future of cms, a simple, easy and intutive content management system ... more

cf prototyping engine, generates boilerplate code and ... more

Jrun monitor
monitor and timely auto-restart to avoid Jrun hang ... more

Inheritance Config.
uses OOPs inheritance to create configuration file ... more

Real Estate App.
complete real estate application using data from MLS ... more

Search Engine Lite
create your own search engine for your web site ... more