I made an Ajax request module using javascript and I store its object to form element attribute formElement.ajax.ajaxmoduleA
.. like this.
After that I want to use this function more easily something like .. formElement.ajaxA()
or assign the function directly on submit event but only I can get is Cannot read properties of undefined
. I presume this happens from this
command inside of object.
class A {
constructor() {
this.a = 'a';
}
getA() {
return this.a;
}
}
el = document.querySelector('#updateNameForm');
el.A = new A;
el.B = el.A.getA;
When I el.A.getA.call()
console, same error pops.. How can I assign object function into element property? How about on event?