17.11.2015 Views

JavaScript_Succinctly

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Table of Contents<br />

About the Author ......................................................................................................... 10<br />

Introduction ................................................................................................................. 11<br />

Preface ......................................................................................................................... 13<br />

More code, less words ............................................................................................... 13<br />

Exhaustive code and repetition .................................................................................. 13<br />

Color-coding conventions .......................................................................................... 13<br />

Code examples .......................................................................................................... 14<br />

Chapter 1: <strong>JavaScript</strong> Objects ................................................................................... 16<br />

Creating objects ......................................................................................................... 16<br />

<strong>JavaScript</strong> constructors create and return object instances ....................................... 21<br />

The native <strong>JavaScript</strong> object constructors ................................................................. 23<br />

User-defined/non-native object constructor functions ................................................ 24<br />

Instantiating constructors using the new operator ...................................................... 25<br />

Creating shorthand or literal values from constructors ............................................... 27<br />

Primitive (aka simple) values ..................................................................................... 28<br />

The primitive values null, undefined, "string", 10, true, and false are not<br />

objects ....................................................................................................................... 30<br />

How primitive values are stored/copied in <strong>JavaScript</strong> ................................................ 31<br />

Primitive values are equal by value ........................................................................... 32<br />

The string, number, and Boolean primitive values act like objects when used like<br />

objects ....................................................................................................................... 33<br />

Complex (aka composite) values ............................................................................... 34<br />

How complex values are stored/copied in <strong>JavaScript</strong> ................................................ 35<br />

Complex objects are equal by reference ................................................................... 36<br />

Complex objects have dynamic properties ................................................................ 37<br />

The typeof operator used on primitive and complex values ..................................... 37<br />

Dynamic properties allow for mutable objects ........................................................... 39<br />

All constructor instances have constructor properties that point to their constructor<br />

function ...................................................................................................................... 40<br />

Verify that an object is an instance of a particular constructor function ..................... 42<br />

An instance created from a constructor can have its own independent properties (aka<br />

instance properties) ................................................................................................... 43<br />

The semantics of "<strong>JavaScript</strong> objects" and "Object() objects" ................................ 44<br />

Chapter 2: Working with Objects and Properties ..................................................... 46<br />

Complex objects can contain most of the <strong>JavaScript</strong> values as properties ................ 46<br />

Encapsulating complex objects in a programmatically beneficial way ....................... 47<br />

Getting, setting, and updating an object's properties using dot notation or bracket<br />

notation ...................................................................................................................... 48<br />

4

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!