<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.
No comments:
Post a Comment