ECMAScript 5 “strict mode” Alternatives

April 1st, 2013 by Mike Wilcox

ES5 offers a way to opt in to a restricted variant of JavaScript by adding strict mode to the top of a page or function. It can be used to access all of the language’s latest features, and have them work with full performance in modern browsers.

However, strict mode is what it sounds like — strict. It can be difficult to learn the new variants and rules. Fortunately ES5 offers other modes that can be used that are more accessible to average coder.

stern mode

Very similar to strict mode. It runs bad code, but tells you all the ways you screwed up and threatens that it won’t run the code next time.

permissive mode

Pretty much let’s you do whatever you want. It’s not happy when you use `with` or `eval`, but doesn’t do anything about it. It will occasionally throw errors, but they are unpredictable and passive aggressive. `switch` and `break` have been removed for being too confrontational and replaced with `praise` and `accept`.

A new exception is introduced for this mode: Fit(). When the feeling is the code is given too much lenience, it’s best to:

throw Fit();

coddle mode

Writes your code for you while you eat snacks.

This mode also includes new exceptions. Up() can be used if the code is taken to extreme. There is a special Party() exception which also returns a special promise. That way you can chain exceptions:

throw Party().then( throw Up(); )

While these new modes are helpful, the TC39 committee realizes they are still to restrictive to be useful is some cases. For ES6, the plan is to release subsections of each from which you can pick and choose. It will be called…

Wait for it…

ala mode

Tags: , , ,

Comments are closed.