Friday, February 1, 2013

Make static class


function foo() {
  var a = 10;
  function bar() {
 a *= 2;
}
bar();
return a;
}
In this example, a is defined in the function foo, but the function bar can access it because
bar is also defined within foo. When bar is executed, it sets a to a times 2. It makes sense that bar
can access a when it is executed within foo, but what if you could execute bar outside of foo?
function foo() {
var a = 10;
function bar() {
a *= 2;
return a;
}
return bar;
}

No comments:

Post a Comment