When I define and call a Function from within a with() statement, the function doesn’t receive the object defined in the with(). Is there a way to solve my problem?
For example, this code doesn’t work:
var testObj = { testStr: "Hello World!" };
with(testObj) {
function testFunc(){
alert(testStr);
}
testFunc();
}
That’s a function declaration.
Functions shouldn’t be declared in statement blocks in the first place.
An expression will work: