Screen ReSize - error ( JavaScript )

When changing the window size, an error occurs which causes the default drawing function to be restored after the "draw" screen.

If I changed the function that will be called to draw on the screen, e.g. draw = drawNew. After changing the screen size of the browser (or only the working area of ​​the screen when working on code in MicroStudio site), the original function that handled drawing is restored.

Here's the demo code.

state = 1234;

init = function() {
  draw = drawNew
  state = "ABCD"
}

update = function() {  
}

draw = function() {
  screen.clear()
  screen.drawText( system.time(), 0, 0, 30, "red")
  screen.drawText( state, 0, 30, 30, "red")  
}

drawNew = function() {
  screen.clear()
  screen.drawText( system.time(), 0, 0, 30, "green")
  screen.drawText( state, 0, 30, 30, "green")   
}

I tried to detect it and restore my function that will draw on the screen - but it turned out to be very difficult because when the screen size is changed, information in other variables is also lost (they are restored to their default state). See the state variable in the example.

In my other code the same thing happens >> https://microstudio.io/i/Loginus/minimal64/

when you resize . Here I tried to save the situation by adding the state variable - but it has the value zero after changing the size. Even though it had a value of 2 before the screen size was changed.