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

133
Vistas
p5.js returns UNDEFINED on this.instance_variable however, works when called explicitly. Please explain why. Example provided

I have read some stack overflow and all I was able to find was that "this" was not referencing the instance variable I had in question and that it was referencing the current window. This did not help my understanding of the problem beyond parroting this back.

I AM ABLE to access the value when I call it explicitly and I have not found this comparison discussed or whether this is convention. See:

class LetterButton {
      constructor(buttonName, text1) {
        console.log(buttonName + " created");
        this.buttonName = createButton(text1);
        this.buttonName.mousePressed(buttonFunction);
        
        function buttonFunction() {
          console.log(buttonName + "*");//<--works     
          console.log(this.buttonName);//<--does not  work UNDEFINED
        } //fn
        
        
      }//constructor
    }//end class
        
    function setup() {
      createCanvas(500, 500);
      background("beige");
      button = new LetterButton("tempButton","tempText") 
      button.buttonName.position(250,250);
    }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I'm pretty sure this is the answer:

You don't have access to this.buttonName within a call from this.buttonName.mousePressed() Though I could be wrong.

about 4 years ago · Juan Pablo Isaza Denunciar
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