Skip to content

Instantly share code, notes, and snippets.

@tshm
Created May 24, 2013 05:10
Show Gist options
  • Save tshm/5641380 to your computer and use it in GitHub Desktop.
Save tshm/5641380 to your computer and use it in GitHub Desktop.
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 );
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment