사고 지도

1498 단어
var commands = {
    up: 1,
    down: 2,
    father: 3,
    child: 4,
};
var commandHandlerFactory = new CommandHandlerFactory();
function Task(content, parent) {
    this.content = content;
    this.childTask = [];
    this.parent = parent;
    this.addChildTask = function (childContent) {
        this.childTask.push(new Task(childContent));
    };
    this.remove = function () {
        this.parent.childTask.remove(this);
    };
    this.edit = function (newContent) {
        this.content = newContent;
    };
}
function Mind(name) {
    this.task = new Task(name, null);
    this.selectTask = this.task;
    this.keyDown = function (e) {
        executeCommand(this.selectTask, e);
    };
}
function executeCommand(selectedTask, e) {
    var command = getCommand(e);
    var handler = commandHandlerFactory.getCommandHandler(command);
    handler.execute(selectedTask);
}
function CommandHandlerFactory() {
    this.commandHandlers = [];
    this.addCommandHandler = function (command, commandHandler) {
        this.commandHandlers.push({ conmmand: command, commandHandler: commandHandler });
    };
    this.getCommandHandler = function (command) {
        for (var i = 0; i < this.commandHandlers.length; i++) {
            if (this.commandHandlers.command == command) {
                return this.commandHandlers.commandHandler;
            }
        }
    };
}
function getCommand(e) {
    //TODO:need to check return which command
    return commands.up;
}

좋은 웹페이지 즐겨찾기