3.07 - constants.js

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

JS
47
字号
var Class = (function() {    // Constants (created as private static attributes).  var UPPER_BOUND = 100;    // Privileged static method.  this.getUPPER_BOUND() {    return UPPER_BOUND;  }  ...  // Return the constructor.  return function(constructorArgument) {    ...  }})();/* Grouping constants together. */var Class = (function() {    // Private static attributes.  var constants = {    UPPER_BOUND: 100,    LOWER_BOUND: -100  }    // Privileged static method.  this.getConstant(name) {    return constants[name];  }  ...  // Return the constructor.  return function(constructorArgument) {    ...  }})();/* Usage. */Class.getConstant('UPPER_BOUND');

⌨️ 快捷键说明

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