Try adding
"use strict";
as the first line of your script.
It may show a few more errors at compile time and may reduce the number of crashes of PI by 20%
Immediately add a valid parent to a GUI object when it is created (this may force creation in a specific order, but this saves quite a few crashes too).
Write Javascript that look like c++ (at least in the GUI part), it seems to work better with the GUI library (cut and paste from existing code).
Isolate the GUI part and the functions (at least for larger scripts), write some programs to execute test systematically or to exercise the GUI without executing the actions. This may it is possible to test the code very often. I found it extremely difficult to track an error if I did a lot of changes since the last test and the only error message is PI crashing.
This helped me but YMMV.
-- bitli