javascript布尔值
Developers are always search for ultimate way to create something with the least amount of code. This, of course, is one of the reasons we use minifiers: to serve code as small as possible. Of course this practice has numerous benefits, like faster download time, less storage consumption, etc. One way that minifiers are able to shave bytes off of JavaScript code is changing the way booleans are used.
开发人员总是在寻找用最少的代码创建某些东西的最终方法。 当然,这是我们使用缩小符的原因之一:尽可能减少代码的产生。 当然,这种做法有很多好处,例如更快的下载时间,更少的存储消耗等。minifier能够从JavaScript代码中减少字节数的一种方法是更改布尔值的使用方式。
true === !0 // Save 2 chars
false === !1 // Save 3 chars
A few bytes of every true and false go away with the ! evaluation. If you set one-letter variables names to those values, you may end up saving more. Keep in mind I'm not telling you to do this in your source code -- minifiers like Uglify JS will do this for you. Just something neat to know about though!
每个正确和错误的几个字节都会消失! 评价。 如果将一个字母的变量名称设置为这些值,则可能会节省更多。 请记住,我没有告诉您在源代码中执行此操作-像Uglify JS这样的压缩程序将为您执行此操作。 只是一些整洁的信息而已!
javascript布尔值