JavaScript Subsets
Most language subsets are defined to allow the secure execution of untrusted code. There is one interesting subset defined for different reasons. We’ll cover that one first, and then cover secure language subsets.
The Good Parts
Douglas Crockford’s short book JavaScript: The Good Parts (O’Reilly) describes a JavaScript subset that consists of the parts of the language that he thinks are worth using. The goal of this subset is to simplify the language, hide quirks and imperfections, and ultimately, make programming easier and programs better. Crockford explains his motivation:
Most programming languages contain good parts and bad parts. I discovered that I could be a better programmer by using only the good parts and avoiding the bad parts.
Crockford’s subset does not include the with
and continue
statements or the eval()
function. It defines functions
using function definition expressions only and does not include the
function declaration statement. The subset requires the bodies of
loops and conditionals to be enclosed in curly braces: it does not
allow the braces to be omitted if the body consists of a single
statement. It requires any statement that does not end with a curly
brace to be terminated with a semicolon.
The subset does not include the comma operator, the bitwise
operators, or the ++
and --
operators. It also disallows ==
and !=
because of the type conversion they
perform, requiring use of ===
and
!==
instead.
Since JavaScript does not have block scope, ...
Get JavaScript: The Definitive Guide, 6th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.