5.06 - comparing the two techniques.js

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

JS
30
字号
/* DataParser singleton, converts character delimited strings into arrays. */ /*   Now using true private methods. */GiantCorp.DataParser = (function() {  // Private attributes.  var whitespaceRegex = /\s+/;    // Private methods.  function stripWhitespace(str) {    return str.replace(whitespaceRegex, '');  }  function stringSplit(str, delimiter) {    return str.split(delimiter);  }    // Everything returned in the object literal is public, but can access the  // members in the closure created above.  return {     // Public method.    stringToArray: function(str, delimiter, stripWS) {      if(stripWS) {        str = stripWhitespace(str);      }      var outputArray = stringSplit(str, delimiter);      return outputArray;    }  };})(); // Invoke the function and assign the returned object literal to      // GiantCorp.DataParser.

⌨️ 快捷键说明

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