Javascript closure

In : Uncategorized, Posted by admin on Mar.03, 2009

A javascript closure is the local variables for a function – kept alive after the function has returned. For example, in the following example, the variable text is still alive after the function is closed. The reason is that the internal function sayAlert is still alive.

function sayHello2(name) {
  var text = 'Hello ' + name; // local variable
  var sayAlert = function() { alert(text); }

  return sayAlert;
}



Source: http://blog.morrisjohns.com/javascript_closures_for_dummies

Tags :

 
close Reblog this comment
blog comments powered by Disqus