Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
js method stored element property cannot access its properties

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?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

  1. You need to use bind to ensure that this is being handled correctly.

  2. You forget to add open/close parentheses to your constructor call: new A().

class A {
    constructor() {
        this.a = 'a';
    }

    getA() {
        return this.a;
    }
}

const el = document.querySelector('#updateNameForm');
el.A = new A();
el.B = el.A.getA.bind(el.A);
console.log(el.B())
<div id="updateNameForm">Form</div>

about 4 years ago · Juan Pablo Isaza Report

0

It might be, because you're syntax is off. You need paranthesis to instantiate a new class or invoke a method:

el = document.querySelector('#updateNameForm');
el.A = new A();
el.B = el.A.getA();
about 4 years ago · Juan Pablo Isaza Report

0

Try fix the line:

el.A = new A();
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!