例子:
function testFunc() {
this.insideFunc = function(msg) {
alert(msg);
}
return this;
}
testFunc().insideFunc("Hi!");
insideFunc("Hi again!");
为什么内部函数在全局范围内可见,如何防止?
最佳答案
那是因为this
是window
。
要以这种方式使用this
,您必须使用:
var _testFunc = new testFunc();
关于javascript - 进行链接时如何使内部函数不超出主函数范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12465082/