(function(){
var privateSomething = "Boom!";
var fn = function(){}
fn.addFunc = function(obj) {
alert('Yeah i can do this: '+privateSomething);
for(var i in obj) fn[i] = obj[i];
}
window.fn=fn;
})();
fn.addFunc({
whereAmI:function()
{
alert('Nope I\'ll get an error here: '+privateSomething);
}
});
fn.whereAmI();
为什么 whereAmI() 不能访问 privateSomething?以及如何将 whereAmI() 放置在与 addFunc() 相同的上下文中?