$(function() {
foo1("text");
foo2("text");
})
function callback(func) {
func();
}
function foo1(bar) {
callback(function() {
console.log(bar); // "text"
bar = "derp";
console.log(bar); // "derp"
})
}
function foo2(bar) {
callback(function() {
console.log(bar); // undefined
var bar = "derp";
console.log(bar); // "derp"
})
}
为什么 var bar = "derp" 的声明未定义预先访问的参数?