Created
July 23, 2010 17:34
-
-
Save polotek/487764 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
diff --git a/src/node.js b/src/node.js | |
index 914f02f..98c9ade 100644 | |
--- a/src/node.js | |
+++ b/src/node.js | |
@@ -192,18 +192,27 @@ process.openStdin = function () { | |
// console object | |
function format (f) { | |
- var i = 1; | |
- var args = arguments; | |
- if (!(f instanceof String)) f = String(f); | |
- return f.replace(/%([sdj])/g, function (x) { | |
- switch (x) { | |
- case '%s': return args[i++]; | |
- case '%d': return args[i++].toString(); | |
- case '%j': return JSON.stringify(args[i++]); | |
+ var sys = module.requireNative('sys'); | |
+ var args = new Array(arguments.length); | |
+ for(var i = 0, len = arguments.length, a; i<len; i++) { | |
+ a = arguments[i]; | |
+ switch (typeof a) { | |
+ case 'string': | |
+ args.push(a); | |
+ break; | |
+ case 'object': | |
+ args.push(sys.inspect(a)); | |
+ break; | |
+ case 'undefined': | |
+ break; | |
default: | |
- return x; | |
- } | |
- }); | |
+ args.push(a.toString()); | |
+ } | |
+ } | |
+ return args.join(' '); | |
} | |
global.console = {}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment