我將如何訪問一個家長的功能「VAR」變量在以下情況下(我只能編輯復位功能的定義):如何在JavaScript中訪問父函數閉包?
_.bind(function(){
var foo = 5;
var reset = function(){
foo = 6; //this changes foo,
bar = 7; //**I want this to add another "var", so I don't pollute global scope
}
reset();
console.log(foo); //6
console.log(bar); //7
}, window);
並且只能在scrope中添加obj – 2012-04-18 01:03:58
而'with'是JavaScript中的一個可怕聲明,其原因很充分。 – tkone 2012-04-18 01:04:06