简体   繁体   English

JavaScript好零件图

[英]JavaScript the Good Parts Diagrams

This question is asked before. 之前问过这个问题。

I have already been to these threads - Thread 1 , Thread 2 我已经去过这些线程- 线程1线程2

I have just started reading JavaScript the Good Parts and it consists of railroad diagrams which i can't understand even after visiting Wikipedia. 我刚刚开始阅读JavaScript的“好零件”,它由铁路图组成,即使访问Wikipedia也无法理解。 You can't just skip them, there are lot's of them. 您不能只跳过它们,其中有很多。 I don't even know why they are so confusing, i found JavaScript to be easy. 我什至不知道为什么他们这么困惑,我发现JavaScript很简单。

Let's take these diagrams for example. 让我们以这些图为例。

分数铁路图

指数铁路图

Correct me if i'm wrong, or just tell me if i am studying these diagrams the right way, below. 如果我错了,请纠正我,或者在下面告诉我是否正在以正确的方式研究这些图表。


For the first diagram , you start from the left, you encounter the "decimal point", Now there are two options. 对于第一个图 ,您从左侧开始,遇到“小数点”,现在有两个选项。 If we just go straight ahead , does that mean only a decimal point without any digit ahead is considered a fraction or is it assumed that there will be a zero ahead by javascript? 如果我们只是直接前进 ,是不是意味着只将小数点前无任何数字的小数点视为小数,或者它是否假定javascript会将零提前?

On the Second Route , we encounter decimal point and then we add a digit to it and then we have a choice either to add more digits in a loop or go ahead and finish with the digit. 在“第二条路线”上 ,我们遇到小数点,然后向其添加一个数字,然后我们可以选择是在循环中添加更多数字,还是继续以该数字结尾。


For the second diagram , I am lost. 对于第二张图 ,我迷路了。

The first diagram means that a fraction is a sequence starting with a dot and followed by zero or more (possibly infinite) digits. 第一个图表示小数是一个以点开头,然后是零个或多个(可能是无限个)数字的序列。

The second diagram means that an exponent starts off with either "e" or "E" then has an optional sign ("-"/"+") and then one or more digits. 第二个图表示指数以“ e”或“ E”开头,然后具有可选的符号(“-” /“ +”),然后是一个或多个数字。

In general those vertical segments with forks show various options that can be taken, while the loop represents that they can be run through zero or multiple times. 通常,那些带有叉子的垂直线段显示了可以采用的各种选项,而循环表示它们可以零次或多次运行。

I had to pull my copy of the book off the shelf, but now I get it. 我不得不将书的副本下架,但现在我明白了。 The railroad diagram for 'fraction' is part of the larger railroad diagram for 'number literal' which looks like: integer[fraction][exponent] . “分数”的铁路图是“数字文字”的较大铁路图的一部分,它看起来像: integer[fraction][exponent] Taken in that context, it's correct... you can have just a dot after the integer part of a number as in var num = 1.; 在这种情况下,这是正确的……您可以在数字的整数部分之后仅加一个点,如var num = 1.;

In the second diagram, branches represent valid choices. 在第二张图中,分支代表有效的选择。 So you start with e or E. Then have a +, -, or nothing (which is the same as +). 因此,您以e或E开头。然后加上+,-或全无(与+相同)。 And finally a sequence of zero or more digits. 最后是零个或多个数字的序列。

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

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