JSFiddle - React, Tailwind, and code Playground
HTML
<button class="setValue">set Value</button>
<button class="getValue">get Value</button>
JavaScript
var MyObject = {
myData: 1,
run: function () {
this.a();
this.b();
},
a: function () {
var self = this;
$('.setValue').click(function () {
self.myData = 2;
});
// even tried like so
},
b: function () {
var self = this;
$('.getValue').click(function () {
alert(self.myData); // should come 2 as value
});
}
}
$(function () {
MyObject.run();
});