Machine.js
jopen
12年前
Machine.js 可以让你使用分层状态机来控制 JavaScript 对象。
// the landscape object - rains or is sunny function Landscape() { this.groundwater = 0; this.oxygen = 0; } Landscape.prototype = { hasWater: function() { return this.groundwater > 0; }, giveWater: function() { this.groundwater -= 1; return 1; }, oxygenate: function() { this.oxygen += 1; }, };