Skip to content

Commit

Permalink
add unregisterMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
capGoblin committed Sep 20, 2023
1 parent fbfac7e commit df205ee
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/core/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,24 @@ class p5 {
target._registeredMethods[name].push(m);
}

unregisterMethod(name, m) {
const target = this || p5.prototype;
if (target._registeredMethods.hasOwnProperty(name)) {
const methods = target._registeredMethods[name];
const indexesToRemove = [];
// Find all indexes of the method `m` in the array of registered methods
for (let i = 0; i < methods.length; i++) {
if (methods[i] === m) {
indexesToRemove.push(i);
}
}
// Remove all instances of the method `m` from the array
for (let i = indexesToRemove.length - 1; i >= 0; i--) {
methods.splice(indexesToRemove[i], 1);
}
}
}

// create a function which provides a standardized process for binding
// globals; this is implemented as a factory primarily so that there's a
// way to redefine what "global" means for the binding function so it
Expand Down

0 comments on commit df205ee

Please sign in to comment.