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

134
Views
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 answers
Answer question

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 Report
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!