JSFiddle - React, Tailwind, and code Playground
HTML
<body>
<div class="">Hello World</div>
<!-- minfied version of my library -->
<script >
class Test {
constructor(selector) {
this.selector = document.querySelector(selector);
this.Object = {};
}
init(content = null) {
if (content == null) {
this.selector.innerHTML = `
<button id="test_btn" type="button">Click Me!</button>
`;
this.Object = {
'name': 'test'
};
this.button = document.getElementById('test_btn');
this.button.addEventListener('click', (event) => {
console.log(this.Object);
// how to return the variable value which is outside of the class Scope
});
}
}
}
</script>
<script type="text/javascript">
// intialise library functionality
const t = new Test('div');
t.init()l
console.log(this.Object)
// How to access the object from here
</script>
</body>