rimlin
rimlin

Reputation: 397

Self-invoking argument changing this to undefined in babel-loader

I am using Webpack with babel-loader, and i see this trouble: babel-loader change this agrument in anonymous self-invoking functions to undefined instead this.

In example:

(function (t1, t2) {
})(this, 'test')

Convert to:

(function (t1, t2) {
})(undefined, 'test');

Upvotes: 1

Views: 759

Answers (1)

Felix Kling
Felix Kling

Reputation: 816790

Babel assumes that every file is a (ES2015) module. A module's this has the value undefined at runtime. To simulate the correct behavior in environments that don't support modules yet (every environment at this time), Babel replaces every top level this with undefined.

Upvotes: 4

Related Questions