Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

143
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda