Proper way of app cleanup on close event?


I have a database running alongside my electron app and when the app closes I need to save some data and shutdown the database.

I thought “onbeforeunload” would do the trick but I forgot that in this case I only have the global scope available in the function bound to the event. Of course I could attach everything I need to the global scope which I’d like to avoid for obvious reasons.

Is there a “properer” way of accomplishing this with electron?


I have been very stupid but since I’m still new to JavaScript I can forgive myself.
Found out that this kind of issue get’s solved via binding the necessary context to the method when assigning it to the event.