16.03 - using interfaces with the command pattern.js

来自「JS设计模式源代码」· JavaScript 代码 · 共 20 行

JS
20
字号
/* Command interface. */var Command = new Interface('Command', ['execute']);/* Checking the interface of a command object. */// Ensure that the execute operation is defined. If not, a descriptive exception// will be thrown.Interface.ensureImplements(someCommand, Command);// If no exception is thrown, you can safely invoke the execute operation. someCommand.execute(); /* Checking command functions. */if(typeof someCommand != 'function') {  throw new Error('Command isn't a function');}

⌨️ 快捷键说明

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