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

Fix referencing isSilent under strict mode #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MasterOdin
Copy link

Fixes db-migrate/node-db-migrate#590

This PR fixes a bug where when running db-migrate under strict mode (such as via its programmable api in a TS script), you'd get an undefined error when trying to reference this.isSilent. This is because under script mode, the this object is made undefined in a function as opposed to referencing the global scope (see "No this substitution" section in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode#changes_in_strict_mode). Instead, we make the isSilent variable accessible on the exports object which gives the same overall characteristics as the global this (such as being accessible and changeable via require), but that exports.isSilent can be safely referenced within the functions.

An alternative approach could be:

this.isSilent = false;
var that = this;

// use that.isSilent everywhere

but this seemed more complicated than using exports.isSilent.

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

Successfully merging this pull request may close these issues.

TypeError when running dbMigrateInstance.up() in strict mode
1 participant