What hides beneath this.var.bind(this)?

Often seen when on() or trigger() hang n the event and as a function add such this.var.bind(this) design. Know what result I can obtain in a given situation, but do not understand what kind of magic she's underneath it.
September 19th 19 at 12:47
3 answers
September 19th 19 at 12:49
In fact, bind returns a special function that already has your this, which you passed to bind as an argument.
frontender.info/demystifying-this-in-javascript/#r...
September 19th 19 at 12:51
method bind()

If you will give just this.val, the context it will be global object (window in a browser). To fix this, use this construction
var that = this;
obj.on('...' , function(/*args*/) {
that.var(/*args*/);
});
//or the same in short
obj.on('...', this.var.bind(this));
September 19th 19 at 12:53
Thank you!

Find more questions by tags JavaScript