闭包可用作缓存
function eater() {
var food = '';
var obj = {
eat: function () {
console.log('i am eating' + ' ' + food);
food = '';
},
push: function (myFood) {
food = myFood;
},
}
return obj;
}
var eater1 = eater();
eater1.push('banana');
eater1.eat();//i am eating banana
标签:闭包,function,缓存,food,用于,var,eater1
From: https://www.cnblogs.com/chengkongfeiniao/p/16608150.html