2
我一直在閱讀這本書,並且帶着很多困難和其他資源,通過這裏完成了它(它本身太難了,但它仍然非常有用,連同其他資源)。Chapter 7,eloquent JavaScript:LifelikeWorld
這是我很難找到的代碼就明白了:
function LifelikeWorld(map, legend) {
World.call(this, map, legend);
}
LifelikeWorld.prototype = Object.create(World.prototype);
var actionTypes = Object.create(null);
LifelikeWorld.prototype.letAct = function(critter, vector) {
var action = critter.act(new View(this, vector));
var handled = action &&
action.type in actionTypes &&
actionTypes[action.type].call(this, critter,
vector, action);
if (!handled) {
critter.energy -= 0.2;
if (critter.energy <= 0)
this.grid.set(vector, null);
}
};
var actionTypes = Object.create(null); //
actionTypes CREAS空對象分辯?
var handled
,我無法理解這個變量,我進入了概念,它是否檢查動作,動作類型是否屬實?並且,actionTypes [action.type] => actionType不是一個空對象?