最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

JavaScript: The Good Parts NamesStrings railroad diagrams confusing - Stack Overflow

programmeradmin4浏览0评论

I started reading JavaScript: The Good Parts book and became confused at first pages (7 and 9 if be exact) by the railroad diagrams.

There are diagrams for the name and the string literal. (you can see the diagrams here)

As I know names in JavaScript can start with letters as well as with underscore or even '$' symbol. Following by the book's diagram it can starts only from letters.

For the string literal, imagine that you want to represent string like that: "\\".
Following by the diagram it's not possible(seems like after the "escaped character" the "any unicode character except " and \ and contol" is required.

Are those an errors in the book? Or I miss something?

I started reading JavaScript: The Good Parts book and became confused at first pages (7 and 9 if be exact) by the railroad diagrams.

There are diagrams for the name and the string literal. (you can see the diagrams here)

As I know names in JavaScript can start with letters as well as with underscore or even '$' symbol. Following by the book's diagram it can starts only from letters.

For the string literal, imagine that you want to represent string like that: "\\".
Following by the diagram it's not possible(seems like after the "escaped character" the "any unicode character except " and \ and contol" is required.

Are those an errors in the book? Or I miss something?

Share Improve this question edited Feb 20, 2015 at 1:49 Kevin Brown-Silva 41.7k42 gold badges206 silver badges243 bronze badges asked Oct 13, 2011 at 20:04 s.matushonoks.matushonok 7,5854 gold badges31 silver badges47 bronze badges 5
  • 1 Here is the list of confirmed errors in the book: oreilly./catalog/errata.csp?isbn=9780596517748 – Marco Mariani Commented Oct 13, 2011 at 20:11
  • 1 The language described in the book "The Good Parts" is not JavaScript but a subset of it - you can call it "Crockford's JavaScript". Crockford introduces new syntax restrictions. One of those restrictions is that names cannot start with $ or _... – Šime Vidas Commented Oct 13, 2011 at 20:11
  • @ŠimeVidas: that would make a good answer... – Ned Batchelder Commented Oct 13, 2011 at 20:14
  • @Marco Mariani Thanks, there is a confirmation on error in the string literal diagram. – s.matushonok Commented Oct 13, 2011 at 20:15
  • @ŠimeVidas: That really makes everything clear. Thank you. Could you post your ment as answer so I'll be able to accept it? – s.matushonok Commented Oct 13, 2011 at 20:18
Add a ment  | 

3 Answers 3

Reset to default 8

The language described in the book "The Good Parts" is not JavaScript but a subset of it - you can call it "Crockford's JavaScript". Crockford introduces new syntax restrictions. One of those restrictions is that names cannot start with $ or _.

It looks like the name railroad diagram definitely has problems. As you say, a name can start with underscore, but the diagram precludes it, and dollar signs seem to be pletely missing.

You're wrong about the string literals though, since "\" is properly not allowed.

One for you, one for Crockford.

JavaScript literal names may start with letters, digits, underscores, or dollar signs. However, it's a convention to use only letters as the first character. http://javascript.crockford./code.html

The string literal may have any escaped character (e.g. "\"" or "\\") or any other character save the delimiter (" or ') and the backslash (\). The escaped character is not a single backslash. It's the representation of the whole escaped character. See the escaped character rail diagram in your own link.

发布评论

评论列表(0)

  1. 暂无评论