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');
}
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.
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 tofxn.call(this)seems to solve this problem.Putting together a PR now.