const self = this is not solving the problem that this could be bound ambiguously. It is simply solving the problem where each function would have their own this. E.g.

const self = this

this

function

function a () { const self = this; return function() { return self.x; } } a.call({ x: 3 })(); // 3

I like using bind to solve this problem tho:

function a () { return (function() { return this.x; }).bind(this); } a.call({ x: 3 })(); // 3

But of course the nicest way would be using arrow functions:

function a () { return () => this.x; } a.call({ x: 3 })(); // 3

We're a place where coders share, stay up-to-date and grow their careers.

We strive for transparency and don't collect excess data.

## re: Is `this` in Javascript bad? VIEW POST

TOP OF THREAD FULL DISCUSSION`const self = this`

is not solving the problem that`this`

could be bound ambiguously. It is simply solving the problem where each`function`

would have their own`this`

. E.g.I like using bind to solve this problem tho:

But of course the nicest way would be using arrow functions: