Created
May 24, 2013 05:10
-
-
Save tshm/5641380 to your computer and use it in GitHub Desktop.
console.log() for jscript.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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