lib/vendor/sugar.js
function stringify(thing, stack) {
    var type = typeof thing,
        thingIsObject,
        thingIsArray,
        klass, value,
        arr, key, i, len;

    // Return quickly if string to save cycles
    if(type === 'string') return thing;

    klass         = internalToString.call(thing)
    thingIsObject = isObject(thing);
    thingIsArray  = klass === '[object Array]';

    if(thing != null && thingIsObject || thingIsArray) {
      // This method for checking for cyclic structures was egregiously stolen from
      // the ingenious method by @kitcambridge from the Underscore script:
      // https://github.com/documentcloud/underscore/issues/240
      if(!stack) stack = [];
      // Allowing a step into the structure before triggering this
      // script to save cycles on standard JSON structures and also to
      // try as hard as possible to catch basic properties that may have
      // been modified.
      if(stack.length > 1) {
        i = stack.length;
        while (i--) {
          if (stack[i] === thing) {
            return 'CYC';
          }
        }
      }
      stack.push(thing);
      value = string(thing.constructor);
      arr = thingIsArray ? thing : object.keys(thing).sort();
      for(i = 0, len = arr.length; i < len; i++) {
        key = thingIsArray ? i : arr[i];
        value += key + stringify(thing[key], stack);
      }
      stack.pop();
    } else if(1 / thing === -Infinity) {
      value = '-0';
    } else {
      value = string(thing && thing.valueOf ? thing.valueOf() : thing);
    }
    return type + klass + value;
  }
function stringify(thing, stack) {
    var type = typeof thing,
        thingIsObject,
        thingIsArray,
        klass, value,
        arr, key, i, len;

    // Return quickly if string to save cycles
    if(type === 'string') return thing;

    klass         = internalToString.call(thing)
    thingIsObject = isObject(thing);
    thingIsArray  = klass === '[object Array]';

    if(thing != null && thingIsObject || thingIsArray) {
      // This method for checking for cyclic structures was egregiously stolen from
      // the ingenious method by @kitcambridge from the Underscore script:
      // https://github.com/documentcloud/underscore/issues/240
      if(!stack) stack = [];
      // Allowing a step into the structure before triggering this
      // script to save cycles on standard JSON structures and also to
      // try as hard as possible to catch basic properties that may have
      // been modified.
      if(stack.length > 1) {
        i = stack.length;
        while (i--) {
          if (stack[i] === thing) {
            return 'CYC';
          }
        }
      }
      stack.push(thing);
      value = string(thing.constructor);
      arr = thingIsArray ? thing : object.keys(thing).sort();
      for(i = 0, len = arr.length; i < len; i++) {
        key = thingIsArray ? i : arr[i];
        value += key + stringify(thing[key], stack);
      }
      stack.pop();
    } else if(1 / thing === -Infinity) {
      value = '-0';
    } else {
      value = string(thing && thing.valueOf ? thing.valueOf() : thing);
    }
    return type + klass + value;
  }
function stringify ( thing , stack ) { var type = typeof thing , thingIsObject , thingIsArray , klass , value , arr , key , i , len ; // Return quickly if string to save cycles if ( type === 'string' ) return thing ; klass = internalToString . call ( thing ) thingIsObject = isObject ( thing ) ; thingIsArray = klass === '[object Array]' ; if ( thing != null && thingIsObject || thingIsArray ) { // This method for checking for cyclic structures was egregiously stolen from // the ingenious method by @kitcambridge from the Underscore script: // https://github.com/documentcloud/underscore/issues/240 if ( ! stack ) stack = [ ] ; // Allowing a step into the structure before triggering this // script to save cycles on standard JSON structures and also to // try as hard as possible to catch basic properties that may have // been modified. if ( stack . length > 1 ) { i = stack . length ; while ( i -- ) { if ( stack [ i ] === thing ) { return 'CYC' ; } } } stack . push ( thing ) ; value = string ( thing . constructor ) ; arr = thingIsArray ? thing : object . keys ( thing ) . sort ( ) ; for ( i = 0 , len = arr . length ; i < len ; i ++ ) { key = thingIsArray ? i : arr [ i ] ; value += key + stringify ( thing [ key ] , stack ) ; } stack . pop ( ) ; } else if ( 1 / thing === - Infinity ) { value = '-0' ; } else { value = string ( thing && thing . valueOf ? thing . valueOf ( ) : thing ) ; } return type + klass + value ; }
Specialized helpers Used by Array#unique and Object.equal
Specialized helpers Used by Array#unique and Object . equal