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

141
Views
Electron, using a method from a custom JavaScript Class

Attempting to build an electron app. I have a Class called Rectangle and I want to have a method of the Class called changeColour() which I can call referencing an instance of the Rectangle Class, like this...

class Rectangle {
  constructor(height, width) {
    //draw a rectangle...
    
    return rectangle;
  }

  changeColour() {
   //do some colour changing...
    return something;
  }
}

module.exports = Rectangle;

In a main.js or main.html I wish to make instances of this Class and to call the method changeColour()

 <script>
      const Rectangle = require('./classes/Rectangle.js');
      const rectangle_1 = new Rectangle(100, 600);
      var elem = document.getElementById('mainDiv');
      elem.appendChild(rectangle_1.rectangle_instance);

      rectangle_1.changeColour();
    </script>
    ```
The instance of Rectangle works fine, but the calling of its method changeColour() throws an error ...

Uncaught TypeError: rectangle_1.changeColour is not a function.

Can anyone help me with solving this error please?
enter code here
about 4 years ago · Juan Pablo Isaza
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!