console.log利用占位符格式化打印
%c表示css样式
console.log('%c hello jefsky', 'color: yellow;font-size: 24px;font-weight: bold;text-decoration: underline;');
%d 或 %i表示整型
console.log('%d', 123);
console.log('%i', 123);
%f表示浮点型
console.log('%f', 123.321);
%o表示DOM元素
console.log('%o', document.body);
%O表示javascript对象
console.log('%O', new Date());
console对象的其他属性
assert: ƒ assert()
clear: ƒ clear()
context: ƒ context()
count: ƒ count()
countReset: ƒ countReset()
debug: ƒ debug()
dir: ƒ dir()
dirxml: ƒ dirxml()
error: ƒ error()
group: ƒ group()
groupCollapsed: ƒ groupCollapsed()
groupEnd: ƒ groupEnd()
info: ƒ info()
log: ƒ log()
memory: (...)
profile: ƒ profile()
profileEnd: ƒ profileEnd()
table: ƒ table()
time: ƒ time()
timeEnd: ƒ timeEnd()
timeLog: ƒ timeLog()
timeStamp: ƒ timeStamp()
trace: ƒ trace()
warn: ƒ warn()
有兴趣的可以在你的浏览器console中尝试一下
著作权归作者所有。
商业转载请联系作者获得授权,非商业转载请注明出处。
作者:JefskyWong ——程序猿甜品店
链接:https://www.jefsky.com/blog/256
来源:https://www.jefsky.com/