举一个刷新列表的例子
//刷新方法
var MenuaBar = {
refresh: function() {
console.log('刷新列表');
}
}
//创建命令
var RefreshMenuBarCommand = function(receiver) {
return {
execute: function() {
receiver.refresh();
}
}
};
//设置命令
var setCommand = function(button, command) {
button.onclick = function() {
command.execute();
}
};
var RefreshMenuBarCommand = RefreshMenuBarCommand(MenuaBar);
setCommand(RefreshMenuBarCommand);