> if (!(this instanceof MyClass)) return new MyClass();
If you really want, just throw an exception and kill the program at compile time. Catch programming errors in testing and not do some magic to 'autocorrect' code.
> var localFile = fs.createWriteStream('localFile.tmp');
Always catch 'error's in stream objects. Otherwise, it might thrown an exception at runtime.
localFile.on('error', /* do something */)
Coding style:
In most cases if you write you code properly, you don't need to nest more than 3-4 levels. If it gets deeper split it out into separate functions. Otherwise, it's a perfect job for async.series.
It's not about "making a mistake", it's about cases where you'd want to create objects but using `new` would be awkward. E.g. `myListOfRawData.map(MyConstructor)` when you unmarshal data. Sure, you could create an anonymous function that calls new. But it's easier to create higher level functions and tools when the new is optional.
Yes, jslint and jshint both do, by default, iirc. They'll also warn on the opposite (using 'new' with a function that doesn't start with an uppercase letter).
If you accidentally forget to use 'new' when you're supposed to, the "constructor" method will change the global object instead of a new object, it can cause strange behavior that is very hard to trace.
> if (!(this instanceof MyClass)) return new MyClass();
If you really want, just throw an exception and kill the program at compile time. Catch programming errors in testing and not do some magic to 'autocorrect' code.
> var localFile = fs.createWriteStream('localFile.tmp');
Always catch 'error's in stream objects. Otherwise, it might thrown an exception at runtime.
localFile.on('error', /* do something */)
Coding style: In most cases if you write you code properly, you don't need to nest more than 3-4 levels. If it gets deeper split it out into separate functions. Otherwise, it's a perfect job for async.series.