Browse Source

console formatter appends extra arguments

This makes the console methods more "browser-like",
for example:

  console.log("foo", "bar", "baz");
  // foo bar baz

but still works with formatting

  console.log("hey %s", "tj", "whats up");

  // hey tj whats up
v0.7.4-release
Tj Holowaychuk 14 years ago
committed by Ryan Dahl
parent
commit
e15221a8de
  1. 6
      src/node.js

6
src/node.js

@ -203,7 +203,7 @@ function format (f) {
var i = 1;
var args = arguments;
return String(f).replace(formatRegExp, function (x) {
var str = String(f).replace(formatRegExp, function (x) {
switch (x) {
case '%s': return args[i++];
case '%d': return +args[i++];
@ -212,6 +212,10 @@ function format (f) {
return x;
}
});
for (var len = args.length; i < len; ++i) {
str += ' ' + args[i];
}
return str;
}
global.console = {};

Loading…
Cancel
Save