web搞两年了,这种写法还真不习惯

解决方案 »

  1.   

    还没帖完
        (function (s) {        // Augment String.prototype. We do this in an immediate anonymous function to
            // avoid defining global variables.        // m is a table of character substitutions.        var m = {
                '\b': '\\b',
                '\t': '\\t',
                '\n': '\\n',
                '\f': '\\f',
                '\r': '\\r',
                '"' : '\\"',
                '\\': '\\\\'
            };        s.parseJSON = function (filter) {            // Parsing happens in three stages. In the first stage, we run the text against
                // a regular expression which looks for non-JSON characters. We are especially
                // concerned with '()' and 'new' because they can cause invocation, and '='
                // because it can cause mutation. But just to be safe, we will reject all
                // unexpected characters.            try {
                    if (/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.
                            test(this)) {                    // In the second stage we use the eval function to compile the text into a
                        // JavaScript structure. The '{' operator is subject to a syntactic ambiguity
                        // in JavaScript: it can begin a block or an object literal. We wrap the text
                        // in parens to eliminate the ambiguity.                    var j = eval('(' + this + ')');                    // In the optional third stage, we recursively walk the new structure, passing
                        // each name/value pair to a filter function for possible transformation.                    if (typeof filter === 'function') {                        function walk(k, v) {
                                if (v && typeof v === 'object') {
                                    for (var i in v) {
                                        if (v.hasOwnProperty(i)) {
                                            v[i] = walk(i, v[i]);
                                        }
                                    }
                                }
                                return filter(k, v);
                            }                        j = walk('', j);
                        }
                        return j;
                    }
                } catch (e) {            // Fall through if the regexp test fails.            }
                throw new SyntaxError("parseJSON");
            };        s.toJSONString = function () {          // If the string contains no control characters, no quote characters, and no
              // backslash characters, then we can simply slap some quotes around it.
              // Otherwise we must also replace the offending characters with safe
              // sequences.          // add by weberliu @ 2007-4-2
              var _self = this.replace("&", "%26");          if (/["\\\x00-\x1f]/.test(this)) {
                  return '"' + _self.replace(/([\x00-\x1f\\"])/g, function(a, b) {
                      var c = m[b];
                      if (c) {
                          return c;
                      }
                      c = b.charCodeAt();
                      return '\\u00' +
                          Math.floor(c / 16).toString(16) +
                          (c % 16).toString(16);
                  }) + '"';
              }
              return '"' + _self + '"';
            };
        })(String.prototype);
    }Ajax.onRunning  = showLoader;
    Ajax.onComplete = hideLoader;
      

  2.   

    用IDE自动生成的,没什么,用上就习惯了。
      

  3.   

    ecshop 的ajax传输类,,,什么时候才能写成这样的代码啊~~~~~~~
    愁啊.....
      

  4.   

    高质量指什么呢?
    速度、效率、稳定性、可读性强等
    像楼主贴的代码,用了全等于判断符号“===”,我想还没有“==”好呢,为什么呢?
    我自己的想法是:既然全等于,那么判断的条件绝对多于“==”,那么CPU判断时,就多执行了几条指令
    以上是个人观点,呵呵呵
      

  5.   

    感觉很好  我搞了2年了...代码之美 !!!97xxoo