Skip to content Skip to sidebar Skip to footer

In Terms Of Efficiency And Elegance, Is It Better To Add And Remove Event Listeners Or Use Global/high-level Variables To Control Emitter Event Logic?

To clarify my question, here are two examples in Javascript-esque pseudo-code. Here are the same examples but with a bit more code to contextualize them: http://pastebin.com/fRjW5q

Solution 1:

I want to clarify 2 things:

  • Node.js is event-driven.
  • Global variables are evil (there's a C/C++ tag but they make the point)

So, in order to keep your code clean and, well, up-to-standards, you should use event-driven approach rather than global variables.

BTW in both cases you do use global variable numberOfSocketsWithBuiltLoginScreens.

Post a Comment for "In Terms Of Efficiency And Elegance, Is It Better To Add And Remove Event Listeners Or Use Global/high-level Variables To Control Emitter Event Logic?"