JSFiddle - React, Tailwind, and code Playground
by podgorniy
JavaScript
var obj = {
handler1 : function () {
console.log('direct binding', this);
},
handler2 : function () {
console.log('with self', this);
},
handler3 : function () {
console.log('with bind()', this);
},
bindEvents : function () {
var self;
self = this;
document.addEventListener('click', this.handler1, false);
document.addEventListener('click', function () {
self.handler2();
}, false);
document.addEventListener('click', this.handler3.bind(this), false);
}
}
obj.bindEvents();