我有以下的Java腳本代碼JavaScript的奇怪行爲,匿名函數
var obj = (function(){
var privateVariable1 = 5;
function privateFunction(){
alert(privateVariable1);
}
obj1 = {};
obj1.publicVariable = privateVariable1;
obj1.publicFunction = function(){
privateFunction();
}
return obj1;
}());
alert(obj.publicFunction());
它警覺的5和不確定。我不明白爲什麼它的alert還未定義。誰能告訴我爲什麼會發生這種行爲?