In JavaScript, functions can always access global variables. I have a class that I am using, and it references global variables. Here's a similar class:
function Test(){
this.abc = abc;
}
If I set the global abc then call this, it works.
var abc = 123,
testA = new Test;
console.log(testA.abc); // 123
But what if I don't want abc to be global? I wrapped the code in a function call, but I get an error saying abc is not defined.
(function(){
var abc = 123,
testA = new Test; // ERROR: abc is not defined
console.log(testA.abc);
})();
How can I read local variables inside a JavaScript constructor without adding variables to the global scope?
abcas a parameter toTest(.)?Test. I was just wondering if I could "fix" it without re-writing. :)