Welcome @user79576 I'm glad you have found enjoyment with the Espruino interpreter.
Although I haven't tried out a fix to your particular issue, I believe the solution is to place the removeListener() function outside your creation of function f() as shown in the online reference:
As the var f is assigned the object result of the function creation, 'connected1' is output as expected, then function f() is created again, 'connected2' is output as expected then the object f() is removed. My guess is that processing is halting at this step as memory is corrupt, and the rest of the statements are ignored as you are seeing.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Sat 2017.07.22
Welcome @user79576 I'm glad you have found enjoyment with the Espruino interpreter.
Although I haven't tried out a fix to your particular issue, I believe the solution is to place the removeListener() function outside your creation of function f() as shown in the online reference:
http://www.espruino.com/Reference#l_Object_removeListener
As the var f is assigned the object result of the function creation, 'connected1' is output as expected, then function f() is created again, 'connected2' is output as expected then the object f() is removed. My guess is that processing is halting at this step as memory is corrupt, and the rest of the statements are ignored as you are seeing.
Also, try:
Other detail
http://www.espruino.com/Reference#Wifi
http://www.espruino.com/Reference#l_Wifi_connected