$(function () {
var CarManager = {
// 請求信息
requestInfo: function (model, id) {
return 'The information for ' + model +
' with ID ' + id + ' is foobar';
},
// 購買汽車
buyVehicle: function (model, id) {
return 'You have successfully purchased Item '
+ id + ', a ' + model;
},
// 組織view
arrangeViewing: function (model, id) {
return 'You have successfully booked a viewing of '
+ model + ' ( ' + id + ' ) ';
}
};
})();
來看一下上述代碼,通過調用函數(shù)來簡單執(zhí)行manager的命令,然而在一些情況下,我們并不想直接調用對象內部的方法。這樣會增加對象與對象間的依賴?,F(xiàn)在我們來擴展一下這個CarManager 使其能夠接受任何來自包括model和car ID 的CarManager對象的處理請求。根據命令模式的定義,我們希望實現(xiàn)如下這種功能的調用:
更多建議: