Today I am learning how to use hot-swapping. I was puzzled when I read the following passage:
It is also important to remove any event listeners from the old instance and re-attach them to the new one.
I tried to comment out this code to run the program, and I manually turned on and off the script during the running of the program, without any errors, the ‘onEnable’ event can still be executed normally, so what is the point of re-attaching the event listeners??
// remove the old event listener old.off('enable', this._onEnable); // add a new event listener this.on('enable', this._onEnable);