2 ms·
Funny, but rather over-stated. Yes, the js runtime is incredibly malleable, and people do indeed load code from everywhere. But there are important, universally
by javajosh 13y ago
Funny, but rather over-stated. Yes, the js runtime is incredibly malleable, and people do indeed load code from everywhere. But there are important, universally adopted conventions that mitigate the risks: the biggest ones being: 1) libraries define a single global variable (or attach themselves as members of one of those global variables). 2) Manipulation of platform prototypes is strictly verboten. 3) Using === in preference to == everywhere.
The "relentless asynchronous" nature of the environment is a challenge but, I'd argue, it's the right challenge. Async programming is actually a Good Thing because you're only ever dealing with a single process, a single path of execution, all the time. It is possible to get this right, whereas with multi-threaded code, I don't think it is, in general. It's true that you can complicate matters by weaving closures in and out of each other to the point where it's impossible to understand the state of your program by reading the source (or even with break points), but that's just bad code, and shouldn't reflect on the notion of async itself.
It really is too bad, though, that the runtime doesn't (and can't) offer better invariant guarantees, and that we have to rely on convention. But honestly, that sort of thing is possible in Java, for example, too. One of your dependancies can load up ASM or BCEL and start changing classes. Heck, Hibernate does this routinely. The only real difference is that the barrier-to-entry for JavaScript programs to do this sort of thing is much lower.