Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
console.log: if not string, coerce into one
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Jun 29, 2010
1 parent 5aadeae commit 6b430a9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/node.js
Expand Up @@ -194,7 +194,7 @@ process.openStdin = function () {
function format (f) {
var i = 1;
var args = arguments;
if (!(f instanceof String)) return f;
if (!(f instanceof String)) f = String(f);

This comment has been minimized.

Copy link
@DmitryBaranovskiy

DmitryBaranovskiy Jun 30, 2010

Just writing
f = String(f);
wouldn’t hurt, because anyway "abc" instanceof String === false

This comment has been minimized.

Copy link
@ry

ry Jun 30, 2010

Author

yeah, I was foolishly thinking this would be faster for the string case.

This comment has been minimized.

Copy link
@eligrey

eligrey Jun 30, 2010

f += "" would also work fine, and is a little shorter. I use it in my libraries to convert stuff to strings.

This comment has been minimized.

Copy link
@tj

tj Jun 30, 2010

''+f

works too

This comment has been minimized.

Copy link
@DmitryBaranovskiy

DmitryBaranovskiy Jun 30, 2010

f += "" is good, but I was taught once that it could be confusing for other developers, later.

This comment has been minimized.

Copy link
@tj

tj Jun 30, 2010

personally I like String() better, feels more like a cast

This comment has been minimized.

Copy link
@TooTallNate

TooTallNate Jun 30, 2010

I 2nd (or 3rd, whichever it is) the String()

return f.replace(/%([sdf])/g, function (x) {
switch (x) {
case '%s': return args[i++];
Expand Down

0 comments on commit 6b430a9

Please sign in to comment.