I was ask why I would introduce a variable to shorten the property path yesterday? For me it was just the subjective feeling that it is easier to read. I'm now wondering if there are any objective reasons to choose one of the two following options (memory consumption, popular convention, ...)?
Option 1:
var errors = require('../errors'),
NotFoundError = errors.NotFoundError;
function example() {
...
new NotFoundError('Item was not found');
}
Option 2:
var errors = require('../errors');
function example() {
...
new error.NotFoundError('Item was not found');
}
Doing this loses context, both in the programming sense (if NotFoundError relies on this being error, it will fail with Option 1 because the context will be different), and the literal sense (averted in this case because Error is in the class name itself, but a more ambiguous name could lead to confusion)
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