Entry level. ES5 standard.
I have built a module:
import Person from './Person.js';
function Employer()
{
Person.call(this);
this.randomMethod = function() {
console.log('randomMethod');
}
this.render = function(elem) {
elem.innerHTML = this.compileTemplate();
}
this.compileTemplate = function() {
return "<p onclick='this.randomMethod()'>Employer block</p>";
}
}
export default Employer;
As you can see, it has its own view. So, now I am able to create as many objects as I want and bind them to DOM elements. As a next step I would like to teach them to execute its own methods (randomMethod in this case) without any global variables. To have a component, which knows how to render itself and how to process its events on es5 without any frameworks.
At least I need to emit a CustomEvent and I wouldn't like to have such long in-line code but a plain method call.
Something similar to Vue components, which have template and methods properties and you can call those methods from template.
Any ideas in this direction?
this.randomMethod, justrandomMethodworks because inline event handlers are invoked as though you called them aslet event=arguments[0]; with(this){eval(attrCode)}. you can also shortenthis.render = function(elem){torender (elem) {if you put it in a class instead of a function.Uncaught ReferenceError: randomMethod is not definedthis.randomMethod()works as expected?thiswithinonclickevent points on<p>html object