Intentando construir una aplicación de electrones. Tengo una Clase llamada Rectangle y quiero tener un método de la Clase llamado changeColour() al que puedo llamar haciendo referencia a una instancia de Rectangle Class, así...
class Rectangle { constructor(height, width) { //draw a rectangle... return rectangle; } changeColour() { //do some colour changing... return something; } } module.exports = Rectangle;En main.js o main.html deseo crear instancias de esta Clase y llamar al método 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