JavaScript
The Good Parts
By Douglas Crockford
Rating | |
Originally published | 2008 |
Tags | Programming |
Started | Jun 27, 2018 |
Finished | Jun 27, 2018 |
Pros
Functions
Loose typing
Simplifies class hierarchies / schemas
Dynamic objects
Expressive object literal notation
“Lightweight and expressive”
Cons
Based on global variables
Gives tools to mitigate this
Blocks do not create a new scope with var declarations
Effectively, it’s “Lisp in C’s clothing”—similar to Lisp / Scheme in features, Java in terms of syntax.
Numbers
There’s only one type; 1.0 and 1 are the same value; avoids floating point errors, others though this makes it harder to deal with integers, type checks, etc.
Good practices
To minimize the negative externalities of global variables, maintain a single global object that contains the rootScope of your app.
Leverage to minimize the need for a global scope.
closure information hiding
Functions
Understand the meaning of this. If a property of an object, this refers to the object itself. If a function defined within an object, this actually refers to the global scope.
arguments is an array-like variable implicitly defined in every function. It is populated with all additional parameters passed in beyond those specified.
← Back to all books