Chapter 1. Code Reuse and Optimization
JavaScript has an undeservedly dubious reputation. Many people have
written about its limitations as an object-oriented programming (OOP)
language, even questioning whether JavaScript is an OOP language at all (it
is). Despite JavaScript’s apparent syntactic resemblance to class-based OOP
languages like C++ and Java, there is no Class statement (or equivalent) in JavaScript, nor
any obvious way to implement popular OOP methodologies such as inheritance
(code reuse) and encapsulation. JavaScript is also very loosely typed, with
no compiler, and hence offers very few errors or warnings when things are
likely to go wrong. The language is too forgiving in almost all instances, a
trait that gives unsuspecting programmers a huge amount of freedom on one
hand, and a mile of rope with which to hang themselves on the
other.
Programmers coming from more classic and strictly defined languages can be frustrated by JavaScript’s blissful ignorance of virtually every programming faux pas imaginable: global functions and variables are the default behavior, and missing semicolons are perfectly acceptable (remember the rope mentioned in the previous paragraph?). Of course, any frustration is probably due to a misunderstanding of what JavaScript is and how it works. Writing JavaScript applications is much easier if programmers first accept a couple of foundational truths:
JavaScript is not a class-based language.
Class-based OOP is not a prerequisite for writing ...