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?
Because static
is reserved in ES3. (not anymore in ES5).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With