我一直在使用LiveScript一段时间,我注意到,在未定义的隐式返回的情况下,使用表达式void 8.
自然,我理解使用void,但我不知道为什么具体使用整数8.
例如,以下LiveScript:
x = if truthy then \success!
将编译为:
var x; x = truthy ? 'success!' : void 8;
解决方法
从LiveScript的文档,这里是他们使用void而不是undefined的推理:
In JavaScript,undefined can be redefined,so it is prudent to use the
void operator which produces the undefined value,always. void at the
top level (not used as an expression) compiles to nothing (for use as
a placeholder) – it must be used as a value to compile.
对于8,这是一个任意数字,可以设定为任何其他数字.根据下面的评论中的讨论,这个特别任意数字的原因是因为LiveScript是coco的一部分,whose wiki reports:
void 8 – the number 8 was chosen because it is a Chinese lucky number.
无论开发人员如何选择这个价值,广义而言,只是LiveScript void编译的.只需要通过void调用来评估一些表达式.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。