⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 16.04 - types of commands.js

📁 JS设计模式源代码
💻 JS
字号:
/* SimpleCommand, a loosely coupled, simple command class. */var SimpleCommand = function(receiver) { // implements Command  this.receiver = receiver;};SimpleCommand.prototype.execute = function() {  this.receiver.action();};/* ComplexCommand, a tightly coupled, complex command class. */var ComplexCommand = function() { // implements Command  this.logger = new Logger();  this.xhrHandler = XhrManager.createXhrHandler();  this.parameters = {};};ComplexCommand.prototype = {  setParameter: function(key, value) {    this.parameters[key] = value;  },  execute: function() {    this.logger.log('Executing command');    var postArray = [];    for(var key in this.parameters) {      postArray.push(key + '=' + this.parameters[key]);    }    var postString = postArray.join('&');    this.xhrHandler.request(      'POST',       'script.php',       function() {},       postString    );  }};/* GreyAreaCommand, somewhere between simple and complex. */var GreyAreaCommand = function(recevier) { // implements Command  this.logger = new Logger();  this.receiver = receiver;};GreyAreaCommand.prototype.execute = function() {  this.logger.log('Executing command');  this.receiver.prepareAction();  this.receiver.action();};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -