From df205eecb0f201336c7e64199df367a1ee39bb94 Mon Sep 17 00:00:00 2001 From: capGoblin Date: Wed, 20 Sep 2023 14:10:21 +0530 Subject: [PATCH] add unregisterMethod --- src/core/main.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/core/main.js b/src/core/main.js index 045ecb632e..f7f94dfbd6 100644 --- a/src/core/main.js +++ b/src/core/main.js @@ -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