Hey! I'm YCMJason, a Software Engineer in London 👨💻. Love diving into tech puzzles and sharing them! 🧩
All views expressed here are my own opinions, so please take them with a pinch of salt! 🧂
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.
The
this
keyword does suck. Your friend is totally right lol. This is why you might seeconst self = this;
in some JS and seeself
used more.const self = this
is not solving the problem thatthis
could be bound ambiguously. It is simply solving the problem where eachfunction
would have their ownthis
. E.g.I like using bind to solve this problem tho:
But of course the nicest way would be using arrow functions: