JSFiddle - React, Tailwind, and code Playground
JavaScript
function test() {
name = "manoj divya";
const self = this;
this.display = function() {
//console.log(this.name); // will not work
console.log(self.name);
}
this.display_arrow = () => {
console.log(this.name); // arrow function will handle this
}
}
const obj = new test();
obj.display();
/* const obj1 = obj.display;
const obj2 = obj.display_arrow;
obj1() */