Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

146
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda