简体   繁体   English

JavaScript三元运算符调用函数或无操作

[英]JavaScript ternary operator calling function or no-op

What is best practice for debugging in JavaScript? 在JavaScript中进行调试的最佳做法是什么?

debugging ? console.log('info') : null;

My question is the null , what is standard practice for this in general, or in this debugging use case? 我的问题是null ,这是一般的标准做法,还是在这个调试用例中?

In your case: 在你的情况下:

debugging && console.log('info');

This trick is based on the "short circuit" feature and I suppose this info might be useful: http://en.wikipedia.org/wiki/Short-circuit_evaluation 这个技巧基于“短路”功能,我想这些信息可能有用: http//en.wikipedia.org/wiki/Short-circuit_evaluation

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

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