关于javascript范围的jquery网站的在线文档我有问题.有代码;
(function() {
var baz = 1;
var bim = function() {
console.log( baz );
};
bar = function() {
console.log( baz );
};
})();
Run Code Online (Sandbox Code Playgroud)
并说:
console.log( baz ); // baz is not defined outside of the function
Run Code Online (Sandbox Code Playgroud)
我不明白的是,即使baz已定义,为什么console.log(baz)未定义.因为我认为范围是一样的.我错过了什么?