var UndoStack = Class.create({
  initialize: function() {
    this.clear();
  },
  addUndoItem: function(undoFn) {
    this._undoItems.push(undoFn);
  },
  undo: function() {
    if(!this.canUndo()) {
      throw new Error("No actions left to undo");
    }
    this._undoItems.pop()();
  },
  canUndo: function() {
    return this._undoItems.length > 0;
  },
  clear: function() {
    this._undoItems = [];
  }
});
