简体   繁体   English

Firebug通过使用或+组合字符串来显示控制台中的字体更改

[英]Firebug shows font change in the console on either the use of , or + to concatonate strings

I have come across an interesting effect on firebug, when using the + operator or the , operator to concatonate strings and then print something to the console the font changes based on which operator you used. 当使用+运算符或,运算符合并字符串,然后将某些字体根据您使用的运算符更改到控制台上时,会在Firebug上产生有趣的效果。

In this case the font for the word Harry changes: 在这种情况下, Harry一词的字体会更改:

在此处输入图片说明

Why does this happen? 为什么会这样? Isn't the comma operator used for concatonation as well? 逗号运算符也不也是吗?

No the comma is not used for concatenation. 没有逗号不用于串联。 console.log will independently log each of its arguments to the same line on the console but if you separate arguments with commas, they will not be concatenated. console.log会将其每个参数独立地记录到控制台上的同一行,但是如果用逗号分隔参数,则它们不会被串联。 The + operator will concatenate them. +运算符将它们连接起来。 For example: 例如:

console.log('hello', {foo: 'bar'}); //=> 'hello', {foo: 'bar'}

console.log('hello' + {foo: 'bar'}); //=> 'hello[object Object]'

Using the + operator, JavaScript will attempt to call .toString on the object in order to concatenate it onto the previous string. JavaScript使用+运算符,将尝试在对象上调用.toString ,以将其连接到先前的字符串。 Using the comma, each piece is considered its own argument passed to console.log which then logs each one. 使用逗号,每件作品都被视为自己的参数,传递给console.log ,然后将其记录console.log

As far as why firebug changes the font, I couldn't say. 至于为什么萤火虫更改字体,我不能说。 What I can say is that it has nothing to do with the actual JavaScript in your application. 可以说的是,它与应用程序中的实际JavaScript没有任何关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM