How can I bind this to a jQuery's event?
For instance, for the push menu below, I have to 'remember' this
to var root
:
class PushMenu {
constructor() {
this.slideShown = false;
var root = this;
$('.navmenu').on('shown.bs.offcanvas', function() {
root.slideShown = true;
});
}
}
But I wonder if I can bind this
so I can save having var root
:
class PushMenu {
constructor() {
this.slideShown = false;
$('.navmenu').on('shown.bs.offcanvas', function() {
this.slideShown = true;
});
}
}
Is this possible?