(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();
Warum kann whereAmI() nicht auf privateSomething zugreifen? und wie platziere ich whereAmI() im selben Kontext wie addFunc()?Javascript Scope in Injected Funktion
'this' ist ein Schlüsselwort keine Variable. Es hat nichts mit Umfang zu tun. – Esailija
Gotcha. Also nicht weiter auf diese Variable huh? – lilturtle
'this' ist eine Referenz auf ein Objekt (oder' undefined') und wird dynamisch aufgelöst. – 1983