I have been using LiveScript for quite a while now, and I have noticed that in situations where undefined
would be implicitly returned, the expression void 8
is used instead.
Naturally, I understand the use of void
, but I cannot figure out why specifically the integer 8
is used.
For an example, the following LiveScript:
x = if truthy then \success!
Will pile to:
var x;
x = truthy ? 'success!' : void 8;
I have been using LiveScript for quite a while now, and I have noticed that in situations where undefined
would be implicitly returned, the expression void 8
is used instead.
Naturally, I understand the use of void
, but I cannot figure out why specifically the integer 8
is used.
For an example, the following LiveScript:
x = if truthy then \success!
Will pile to:
var x;
x = truthy ? 'success!' : void 8;
Share
Improve this question
edited May 30, 2014 at 17:35
Dormouse
5,1781 gold badge28 silver badges42 bronze badges
asked May 30, 2014 at 17:34
Jim O'BrienJim O'Brien
2,53718 silver badges29 bronze badges
5
-
With some imagination,
void 8
reads like "voided". That must be it :P In any case, that's one of these questions you should ask the developers directly. – Felix Kling Commented May 30, 2014 at 17:41 -
I guess it's the same reason most people use
void 0
. – Oriol Commented May 30, 2014 at 17:42 - 3 I was thoroughly and hopelessly confused when I first saw this question because LiveScript was the original name of JavaScript in early Netscape builds where the scripting language first appeared and I was wondering what on earth someone was doing writing code for pre-NN4. So it turns out there's a new language, based on JavaScript, that goes by the name LiveScript... go figure. – BoltClock Commented May 30, 2014 at 17:44
- @BoltClock Sometimes really new is well forgotten old. – VisioN Commented May 30, 2014 at 17:46
-
I show my age, but to me 8 was always an error
JCL Return Code=8(Error)
– mplungjan Commented May 30, 2014 at 17:54
2 Answers
Reset to default 6From the documentation on LiveScript, here's their reasoning for using void
rather than 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) piles to nothing (for use as a placeholder) - it must be used as a value to pile.
As for the 8
, it's an arbitrary number, and could have been set to any other. As per discussion in the ments below, the reason for this particular arbitrary number is because LiveScript is a fork of coco, whose wiki reports:
void 8 - the number 8 was chosen because it is a Chinese lucky number.
Regardless of how the developers chose the value, broadly speaking, it's just what the LiveScript void
piles to. There just has to be some expression evaluated by the void
call.
Most probably 8
is the favourite number of the developer (or just a random number), as whatever you put after void
operator, you'll receive pure, not overridden undefined
.
Simple test:
void 0 === void 8 => true
void 'a' === void 8 => true
void true === void 8 => true
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745266282a4619476.html
评论列表(0条)