DFOXpro
DFOXpro

Reputation: 353

How to tell BabelJS not to override this

Babel is replacing this with void 0 how can I prevent this behavior?

I have this code:

((parent)=>{
  parent.something = {}
})(this)

With babel it renders like

(function (parent) {
  parent.something = {}
})(void 0);

I need this

(function (parent) {
  parent.something = {}
})(this);

I know that I can use self but this is not the same in all cases

Upvotes: 4

Views: 967

Answers (1)

DFOXpro
DFOXpro

Reputation: 353

In the babelrc file or your bundler config set babel with:

presets: [["@babel/preset-env", { modules: false }]]

Note the double brackets, reason here

Upvotes: 6

Related Questions