Skip to content

Commit ad206b7

Browse files
committed
Avoid double-binding prototype methods
1 parent ba4c808 commit ad206b7

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/core/main.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class p5 {
7878
this._updateWindowSize();
7979

8080
// Apply addon defined decorations
81+
p5.prototype.__originalMethods = p5.prototype.__originalMethods || {};
8182
for(const [patternArray, decoration] of p5.decorations){
8283
for(const member in p5.prototype){
8384
// Member must be a function
@@ -91,7 +92,10 @@ class p5 {
9192
}
9293
})) continue;
9394

94-
const copy = p5.prototype[member].bind(this);
95+
// Store a copy of the original, unbound prototype method so that if we make a new p5 instance
96+
// later, we don't double-, triple-, etc bind the function
97+
p5.prototype.__originalMethods[member] = p5.prototype.__originalMethods[member] || p5.prototype[member];
98+
const copy = p5.prototype.__originalMethods[member].bind(this);
9599
p5.prototype[member] = decoration.call(this, copy, member);
96100
}
97101
}

0 commit comments

Comments
 (0)