Twelve poetic characters/keystrokes of javascript that can change the world

What is this?

Javascript is the programming language of the web. However, there is something seriously wrong with it: eval. The mere existance of eval plunges the world of javascript into dark evil illperformance. However, there exists a magical savior from heaven known only to the very few with the luck to happen by it: Function. This article aims to show why eval is evil, how we can use the good alternative named Function, then finally how we can exorcise the evil demon from hell named eval in only 16 Internet-Explorer-5-compatible characters of javascript.

History and Background

Back in the 90's, javascript was a massively different landscape. Take the following code snippet.
var foo = "random str"; var bar = {"prop": foo}; Back then, browsers read javascript line by line and constructed associative lookup tables of the names of variables. The lookup table for the above snippet would look something like this.


Function To The Rescue



The 16 Elegant Characters Of Perfection

Below are the 16 characters of javascript that will exorcise all the evils of eval.
delete self.eval;
The above code snippet works by deleting the one single global reference to eval

How You Can Make The World A Better Place

Keep this article in mind every time you write new code and put in the magical snippet delete self.eval; right after the "use strict"; at the top of the first javascript file of every html page you write. Also include this snippet at the top of all worker scripts and NodeJS scripts. While Browsers do not optimize for this yet, browsers will certainly optimize for this in the future when there grows to be a big enough community of developers utilizing theese 16 poetic keystrokes of javascript.

If You Are A Browser Dev

If you are part of the team working on a browser, then here is how you can implement this optimization while maintaining full EcmaScript standards compliance. Simply, when the very first snippet of javascript is parsed and runned on the page, check to see if (when the whitespace is taken out) the file starts with "use strict;"delete self.eval;. If the file does start with this, then your JIST compile will be able to make assumptions never before thought possible, and potentially make the memory efficiency of the javascript code several fold faster.