, .
var factory = function(someCondition) {
var para1 = 'some value';
if(someCondition){
var para2 = 'some other value';
alert(para2);
}
alert(para2);
return new MyClass(para1, para2);
}
, . . if para2. , " "!. . , , , if, " "!.
This is what happens. Your variable para2 is declared internally if it is known as a block. A block is all that appears in open and closed brackets - {and}. In many programming languages, variables declared inside a block are part of its own area of the block. This means that these variables are local and cannot be accessed outside the block.
JavaScript is not like many other programming languages. JavaScript does not support scope browsing.
More here
source
share