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 : javascript
Add New Comment
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Add New Comment