GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Sunday, January 30, 2011

Javascript Closure

<script>

(function(){
    var name = 'Lady Gaga';
    alert(name);    // executed
}();

alert(name);    // doesn't reach this outer calling

</script>

What the benefit of the closure? The benefit is that the code is not accessible from the outer scope. The scope is executed normally once. But you cannot call it from the outer closure.

Share/Bookmark

No comments:

Post a Comment