Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor hoisted and locally-redeclarated variables #5

Closed
michaelsanford opened this issue Sep 23, 2014 · 1 comment
Closed

Refactor hoisted and locally-redeclarated variables #5

michaelsanford opened this issue Sep 23, 2014 · 1 comment

Comments

@michaelsanford
Copy link
Contributor

The err variable declared in lib/runner.js:137 will be overwritten by the one in :153 because those variables live in the same scope.

To mitigate this problem, I avoided creating a variable at all and refactored by inlining the object into the call to emit(), which is no less readable and slightly more efficient (avoids a variable assignment).

Sort of similarly, we can't re-scope a named parameter with var, as in lib/debug-helper.js:9. That line could be improved (and made slightly safer) by being changed to:

module.exports = function (logger) {
  // other code
  logger = typeof logger !== 'undefined' ? logger : console;`
  // other code
}
@michaelsanford michaelsanford mentioned this issue Sep 23, 2014
3 tasks
@michaelsanford
Copy link
Contributor Author

After looking at it again, it is actually inefficient to emit directly. To avoid hoisting and reassignment, I've split the errors into two variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant