P5.js: p5 dom library did not set binding DOM element as Default

Created on 7 Oct 2018  ·  4Comments  ·  Source: processing/p5.js

Nature of issue?

  • [x ] Found a bug
  • [ ] Existing feature enhancement
  • [ ] New feature request

Most appropriate sub-area of p5.js?

  • [ ] Color
  • [ ] Core/Environment/Rendering
  • [ ] Data
  • [x ] Events
  • [ ] Image
  • [ ] IO
  • [ ] Math
  • [ ] Typography
  • [ ] Utilities
  • [ ] WebGL
  • [ ] Other (specify if possible)

Which platform were you using when you encountered this?

  • [ ] Mobile/Tablet (touch devices)
  • [x ] Desktop/Laptop
  • [ ] Others (specify if possible)

Details about the bug:

  • p5.js version: 0.7.2
  • Web browser and version: 69.0.3497.100
  • Operating System: windows10
  • Steps to reproduce this:

The dom library is actually supposed to bind the DOM element behind the scenes.
However,the feedback in console shows “Uncaught TypeError: this.class is not a function .”

function setup() {
  noCanvas();
  button = createButton('hello');
  button.mousePressed(test);
}

function test() {
  console.log("test");
  this.html('goodbye');
} 
dom

Most helpful comment

The user's callback here: https://github.com/processing/p5.js/blob/master/src/core/p5.Element.js#L242 is not called with the correct context instead the internal function has its context bound with adjustListener, so changing the function call to fxn.call(this) seems to solve this problem.

Putting together a PR now.

All 4 comments

I've tested this and can confirm the issue. The above code from @Leiyufazhuangjia works in version 0.6.1 but not in any of the 0.7.x versions.

Is this perhaps related to #3185?

The behaviour in 0.7.2 and 0.7.1 and below are different, I'm looking into this now

@Spongman Problem exist before that, though it changed the behaviour of the bug

The user's callback here: https://github.com/processing/p5.js/blob/master/src/core/p5.Element.js#L242 is not called with the correct context instead the internal function has its context bound with adjustListener, so changing the function call to fxn.call(this) seems to solve this problem.

Putting together a PR now.

Was this page helpful?
0 / 5 - 0 ratings