例子代码类似如下
log(logObj) {
const consoleLogFn = this._getLogFn(logObj.level);
// Type
const type = logObj.type === 'log' ? '' : logObj.type;
// Tag
const tag = logObj.tag || '';
// Styles
const color =
this.typeColorMap[logObj.type] ||
this.levelColorMap[logObj.level] ||
this.defaultColor;
const style = `
background: ${color};
border-radius: 0.5em;
color: white;
font-weight: bold;
padding: 2px 0.5em;
`;
const badge = `%c${[tag, type].filter(Boolean).join(':')}`;
// Log to the console
if (typeof logObj.args[0] === 'string') {
consoleLogFn(
`${badge}%c ${logObj.args[0]}`,
style,
// Empty string as style resets to default console style
'',
...logObj.args.slice(1)
);
} else {
consoleLogFn(badge, style, ...logObj.args);
}
}
2.首先第一个问题 logObj 就难住了调用者,这个 logObj 是什么,有什么属性,每个属性是做什么用的?
Question