我有以下匿名职能:
(function() {
var a = 1;
var b = 2;
function f1() {
}
function f2() {
}
// this => window object!
// externalFunction(this);
})();
function externalFunction(pointer) {
// pointer.f1(); => fail!
}
I need to call external function from this anonymous function and pass it s pointer to call functions f1 & f2. But I can t do this, as this refer to window object instead of internal scope.
我可以确定以下职能:
this.f1 = function() {}
但它却带有坏思想,因为它们在全球空间中消失......
我如何通过匿名空间来履行外部职能?