Skip to content

Instantly share code, notes, and snippets.

@polotek
Created July 23, 2010 17:34
Show Gist options
  • Save polotek/487764 to your computer and use it in GitHub Desktop.
Save polotek/487764 to your computer and use it in GitHub Desktop.
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