// 設置命令 var setCommand = function(button, func) { button.onclick = function () { func(); } } // 命令集合 var MenuBar = { refresh: function() { console.log('刷新菜單界面'); } }; // 命令觸發條件 receiver 接受者 var RefreshMenuBarCommand = function (receiver) { return function() { receiver.refresh(); } } var refreshMenuBarCommand = RefreshMenuBarCommand(MenuBar); // 綁定命令 setCommand(button1, refreshMenuBarCommand);