JavaScript’s nature can be summarized as follows:
bind()
, built-in map()
and reduce()
for arrays, etc.) and object-oriented programming (mutable state, objects, inheritance, etc.).
Note that JavaScript engines have become quite smart and fix some of the quirks, under the hood. For example:
But JavaScript also has many elegant parts. Brendan Eich’s favorites are:[3]
The last two items, object literals and array literals, let you start with objects and introduce abstractions (such as constructors, JavaScript’s analog to classes) later. They also enable JSON (see Chapter 22).
Note that the elegant parts help you work around the quirks. For example, they allow you to implement block scoping, modules, and inheritance APIs—all within the language.
JavaScript was influenced by several programming languages (as shown in Figure 3-1):
Date
constructor (which is a port of java.util.Date
).
function
comes from AWK.
onclick
.