After some checking, I found the culprit and yes, the problem is that it is "name"used in a special way.
JavaScript, Node REPL, .
, :
function formatObject(ctx, value, recurseTimes, visibleKeys, keys) {
return keys.map(function(key) {
return formatProperty(ctx, value, recurseTimes, visibleKeys, key, false);
});
}
value Object.prototype, .. { name: 'bar' } keys - , .. ["name"].
"name" formatProperty, / formatValue . , , - "[32m'bar'[39m".
, . , , [Object], [Getter] .. :
ctx.stylize(name, 'name');
name "name", 'name' , , 'name' .
, stylize stylizeWithColor, ctx.colors .
stylizeWithColor .
function stylizeWithColor(str, styleType) {
var style = inspect.styles[styleType];
if (style) {
return `\u001b[${inspect.colors[style][0]}m${str}` +
`\u001b[${inspect.colors[style][1]}m`;
} else {
return str;
}
}
?
, stylizeWithColor 'name' styleType, styleType :
boolean
date
null
number
regexp
special
string
symbol
undefined
'name' , .
inspect.styles, inspect.styles['name'] undefined ( ) if.
var style = inspect.styles[styleType];
if (style) {
, inspect.styles POJO "name" Object.prototype, inspect.styles['name'] 'name' , [[Prototype]] "bar".
var style = inspect.styles[styleType];
if (style) {
, inspect.colors["bar"][0], inspect.colors - POJO, . , "bar" .
, undefined[0], .
, name , inspect.colors, , name .

: , , inspect.styles , .