Today I ran into this piece of code
From time to time, unexpected behavior can popup while programming.
Here is one I would like to write down.
|
|
It is an object factory.
It will return an object that have one member, factoryObject
which is a string containing Factory made
inside it when the unnamed function being called by other scripts.
The following code won’t run in Node.js v5.5.0
|
|
The code will crash ultimately with following error:
|
|
So we learned an important lesson here.
Conclusion
The real reason is actually the automatic semicolon insertion .
Just don’t put curly bracket in their own line, expesically when the line above can be valid itself.
For example return
.