Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bracket and dot notation in compiled CoffeeScript

I have this piece of code in a Node/Express app:

app.use "/static", express.directory("#{__dirname}/public")
app.use "/static", express.static("#{__dirname}/public")

It compiles to this:

app.use("/static", express.directory("" + __dirname + "/public"));
app.use("/static", express["static"]("" + __dirname + "/public"));

By curiosity, I am wondering: why is the dot notation used for the first call and the bracket notation for the second call?

like image 829
conradkleinespel Avatar asked Feb 16 '23 05:02

conradkleinespel


2 Answers

Because static is reserved in ES3. (not anymore in ES5).

like image 139
Ven Avatar answered Feb 18 '23 20:02

Ven


Because static is a reserved word in Javascript prior to EcmaScript 5 .

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Reserved_Words

Some browsers might throw an error if it is used as an object property with the object.word syntax .

object['word'] ensure no error will be thrown.

like image 35
mpm Avatar answered Feb 18 '23 19:02

mpm