funtion test () {
var food = "apple";
var obj = {
eatFood : function () {
if (food != " "){
console.log("www");
} else {
cosole.log ("222")
}
}
pushFood :function (myFood){
food = myFood;
}
}
return obj;
}
var Person = test();
Person.eatFood();
Person.eatFood();
Person.PushFood("banana");
Person.eatFood();
注:互相修改有连带性,(多个函数和一个函数形成变量公用的一个变量)