用布尔值(someVar)替换!! someVar是否100%正确? [英] Is it 100% correct to replace !!someVar with Boolean(someVar)?
问题描述
我正在重构一堆旧代码并看到JSCS显示有关隐式类型转换的警告!! someVar语句。
I am refactoring a bunch of old code and see that JSCS shows a warning about implicit type conversion for !!someVar statements.
用Boolean(someVar)替换所有这些隐式转换是否正确,以免因此更改而中断?
Is it correct to replace all these implicit conversions with Boolean(someVar) so that nothing breaks due to this change?
推荐答案
用<替换
!! someVar
100%是否正确code>布尔值(someVar)?
Is it 100% correct to replace
!!someVar
withBoolean(someVar)
?
否。全局 Boolean
变量可能会被覆盖/隐藏, !!
运算符不能。
No. The global Boolean
variable might be overwritten/shadowed, the !!
operators cannot.
用<$替换所有这些隐式转换是否正确c $ c>布尔值(someVar)以便不会因此更改而中断任何内容?
Is it correct to replace all these implicit conversions with
Boolean(someVar)
so that nothing breaks due to this change?
是。如果您的代码由于此更改而中断,则应将其视为已经损坏,并且您应该使用 Boolean
来修复混乱。
Yes. If your code breaks because of this change, it should be considered already broken, and you should fix the thing that messes with Boolean
instead.
这篇关于用布尔值(someVar)替换!! someVar是否100%正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!