tshm
5/24/2013 - 5:10 AM

console.log() for jscript.

console.log() for jscript.

var console = {
  log: function( v ) {
    var str = (function stringify( obj, unquote ) {
      if ( obj === null ) return 'null';
      if ( obj === undefined ) return 'undefined';
      if ( obj instanceof Array ) {
        var str = [];
        for ( var i = 0; i < obj.length; ++i ) {
          str.push( stringify( obj[i] ));
        }
        return '[ ' + str.join(', ') + ' ]';
      }
      var type = typeof obj;
      if ( type === 'string' ) {
        if ( !unquote ) return '"' + obj + '"';
        return obj;
      }
      if ( type === 'object' ) {
        var str = [];
        for ( var p in obj ) {
          str.push( stringify( p, true ) + ': ' + stringify( obj[p] ));
        }
        return '{ ' + str.join(', ') + ' }';
      }
      if ( type === 'function' ) return 'function';
      return obj.toString ? obj.toString() : type;
    })( v );
    WScript.Echo( str );
  }
};