Javascript最小化为什么将false替换为!1并将true替换为!0 [英] Javascript minification why is false replaced with !1 and true with !0

查看:213
本文介绍了Javascript最小化为什么将false替换为!1并将true替换为!0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Enyo2编写一个应用程序,该应用程序带有一个基于UglifyJS的缩小工具. 我注意到了:

I'm writing an app using Enyo2 which comes with a minification tool based on UglifyJS. I've noticed that:

var t = false

替换为

var t=!1

用!0代替true.我敢肯定有一个很好的解释,我只是找不到.有什么主意吗?

The same way true is replaced with !0. I'm sure there is a good explanation for that, I just can't find it. Any idea?

推荐答案

显然有一个.如果使用1或0转换为true或false,则它会更短一些,但被视为整数.如果添加!在前面并反转它们,它将合并为布尔值并且仍然很短.

There is one apparently. If you use 1 or 0 to translate true or false, it would be shorter but seen as integers. If you add ! in front and reverse them, it will be coalesced into booleans and still be short.

这篇关于Javascript最小化为什么将false替换为!1并将true替换为!0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆