Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript: The Good Parts Names/Strings railroad diagrams confusing

Tags:

javascript

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?

like image 923
mt_serg Avatar asked Oct 13 '11 20:10

mt_serg


2 Answers

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 _.

like image 87
Šime Vidas Avatar answered Oct 04 '22 23:10

Šime Vidas


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 completely missing.

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

One for you, one for Crockford.

like image 30
Ned Batchelder Avatar answered Oct 04 '22 22:10

Ned Batchelder