Binding actions once to the stop button

I was wondering how can you bind functions to the stop event (and only do so once) likely via JS. I need to use this for my Oscillator Toolkit so that the oscillators do not continue playing once the program has been stopped. I know that I can use something like this, but it will probably be something people forget to do:
Oscillators script pic

If by "playing" you mean "making noise," I'd say that will be a self-correcting case of forgetfulness! :~)

Yea, I basically want them to stop going boooooooooooooooooooooooooooooooooooooooooooooooop when I hit stop without needing to include that tidbit. [stop all oscillators] loops through this.oscillators and calls .disconnect() on all playing oscillators.

I faced a similar problem (with speech recognition and synthesis) and dealt with by running this once:

const ide = get_snap_ide();
const original_stopAllScripts = ide.stopAllScripts.bind(ide);
ide.stopAllScripts = function () {
       stop_all_scripts();
       original_stopAllScripts();
};