Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 694
DFOXpro Avatar asked Sep 05 '25 03:09

DFOXpro


1 Answers

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

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

Note the double brackets, reason here

like image 118
DFOXpro Avatar answered Sep 08 '25 01:09

DFOXpro