JavaScript Enlightenment

Book description

If you’re an advanced beginner or intermediate JavaScript developer, JavaScript Enlightenment will solidify your understanding of the language—especially if you use a JavaScript library. In this concise book, JavaScript expert Cody Lindley (jQuery Cookbook) provides an accurate view of the language by examining its objects and supporting nuances.

Libraries and frameworks help you build web applications quickly and efficiently, but when things go wrong or performance becomes an issue, knowing how and why they work is critical. If you’re ready to go under the hood and get your hands dirty with JavaScript internals, this is your book.

  • Get a short and digestible summary of ECMA-262, Edition 3, backed by real code you can run instantly
  • Examine the creation of JavaScript objects
  • Learn complex values, primitive values, scope, and inheritance
  • Understand the importance of the head object
  • Work with string, number, and Boolean objects and values
  • Discover how to use the null value and the built-in math object
  • Get into the details—beyond Mozilla’s reference guide for JavaScript 1.5

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Introduction
      1. Why Did I Write This Book?
      2. Who Should Read This Book?
      3. Why JavaScript 1.5 and ECMAScript 3 Edition?
      4. Why Didn’t I Cover the Date(), Error(), and RegEx() Objects?
    2. More Code, Fewer Words
    3. Exhaustive Code and Repetition
    4. Color-Coding Conventions
    5. jsFiddle, JS Bin, and Firebug lite-dev
    6. Conventions Used in This Book
    7. Using Code Examples
    8. Safari® Books Online
    9. How to Contact Us
    10. About the Author
    11. About the Technical Editors
      1. Michael Richardson
      2. Kyle Simpson
      3. Nathan Smith
      4. Ben Nadel
      5. Ryan Florence
      6. Nathan Logan
  2. 1. JavaScript Objects
    1. Creating Objects
    2. JavaScript Constructors Construct and Return Object Instances
    3. The JavaScript Native/Built-In Object Constructors
    4. User-Defined/Non-Native Object Constructor Functions
    5. Instantiating Constructors Using the new Operator
    6. Creating Shorthand/Literal Values from Constructors
    7. Primitive (a.k.a. Simple) Values
    8. The Primitive Values null, undefined, “string”, 10, true, and false Are Not Objects
    9. How Primitive Values Are Stored/Copied in JavaScript
    10. Primitive Values Are Equal by Value
    11. The String, Number, and Boolean Primitive Values Act Like Objects When Used Like Objects
    12. Complex (a.k.a. Composite) Values
    13. How Complex Values Are Stored/Copied in JavaScript
    14. Complex Objects Are Equal by Reference
    15. Complex Objects Have Dynamic Properties
    16. The typeof Operator Used on Primitive and Complex Values
    17. Dynamic Properties Allow for Mutable Objects
    18. All Constructor Instances Have Constructor Properties that Point to Their Constructor Function
    19. Verify that an Object Is an Instance of a Particular Constructor Function
    20. An Instance Created From a Constructor Can Have Its Own Independent Properties (Instance Properties)
    21. The Semantics of “JavaScript Objects” and “Object() Objects”
  3. 2. Working with Objects and Properties
    1. Complex Objects Can Contain Most of the JavaScript Values as Properties
    2. Encapsulating Complex Objects in a Programmatically Beneficial Way
    3. Getting/Setting/Updating an Object’s Properties Using Dot Notation or Bracket Notation
    4. Deleting Object Properties
    5. How References to Object Properties Are Resolved
    6. Using hasOwnProperty, Verify That an Object Property Is Not From the Prototype Chain
    7. Checking If an Object Contains a Given Property Using the in Operator
    8. Enumerate (Loop Over) an Object’s Properties using the for in Loop
    9. Host Objects versus Native Objects
    10. Enhancing and Extending Objects with Underscore.js
  4. 3. Object()
    1. Conceptual Overview of Using Object() Objects
    2. Object() Parameters
    3. Object() Properties and Methods
    4. Object() Object Instance Properties and Methods
    5. Creating Object() Objects Using “Object Literals”
    6. All Objects Inherit From Object.prototype
  5. 4. Function()
    1. Conceptual Overview of Using Function() Objects
    2. Function() Parameters
    3. Function() Properties and Methods
    4. Function Object Instance Properties and Methods
    5. Functions Always Return a Value
    6. Functions Are First-Class Citizens (Not Just Syntax but Values)
    7. Passing Parameters to a Function
    8. this and arguments Values Available To All Functions
    9. The arguments.callee Property
    10. The Function Instance length Property and arguments.length
    11. Redefining Function Parameters
    12. Return a Function Before It Is Done (Cancel Function Execution)
    13. Defining a Function (Statement, Expression, or Constructor)
    14. Invoking a Function [Function, Method, Constructor, or call() and apply()]
    15. Anonymous Functions
    16. Self-Invoking Function Expression
    17. Self-Invoking Anonymous Function Statements
    18. Functions Can Be Nested
    19. Passing Functions to Functions and Returning Functions from Functions
    20. Invoking Function Statements Before They Are Defined (Function Hoisting)
    21. A Function Can Call Itself (Recursion)
  6. 5. The Head/Global Object
    1. Conceptual Overview of the Head Object
    2. Global Functions Contained Within the Head Object
    3. The Head Object versus Global Properties and Global Variables
    4. Referring to the Head Object
    5. The Head Object Is Implied and Typically Not Referenced Explicitly
  7. 6. The this Keyword
    1. Conceptual Overview of this and How It Refers to Objects
    2. How Is the Value of this Determined?
    3. The this Keyword Refers to the Head Object in Nested Functions
    4. Working Around the Nested Function Issue by Leveraging the Scope Chain
    5. Controlling the Value of this Using call() or apply()
    6. Using the this Keyword Inside a User-Defined Constructor Function
    7. The this Keyword Inside a Prototype Method Refers to a Constructor Instance
  8. 7. Scope and Closures
    1. Conceptual Overview of JavaScript Scope
    2. JavaScript Does Not Have Block Scope
    3. Use var Inside Functions to Declare Variables and Avoid Scope Gotchas
    4. The Scope Chain (Lexical Scoping)
    5. The Scope Chain Lookup Returns the First Found Value
    6. Scope Is Determined During Function Definition, not Invocation
    7. Closures Are Caused by the Scope Chain
  9. 8. Function Prototype Property
    1. Conceptual Overview of the Prototype Chain
    2. Why Care About the prototype Property?
    3. Prototype Is Standard on All function() Instances
    4. The Default prototype Property Is an Object() Object
    5. Instances Created From a Constructor Function are Linked to the Constructor’s prototype Property
    6. Last Stop in the prototype Chain is Object.prototype
    7. The prototype Chain Returns the First Property Match It Finds in the Chain
    8. Replacing the prototype Property with a New Object Removes the Default Constructor Property
    9. Instances That Inherit Properties from the Prototype Will Always Get the Latest Values
    10. Replacing the prototype Property with a New Object Does Not Update Former Instances
    11. User-Defined Constructors Can Leverage the Same Prototype Inheritance as Native Constructors
    12. Creating Inheritance Chains (the Original Intention)
  10. 9. Array()
    1. Conceptual Overview of Using Array() Objects
    2. Array() Parameters
    3. Array() Properties and Methods
    4. Array Object Instance Properties and Methods
    5. Creating Arrays
    6. Adding and Updating Values in Arrays
    7. Length versus Index
    8. Defining Arrays with a Predefined Length
    9. Setting Array Length can Add or Remove Values
    10. Arrays Containing Other Arrays (Multidimensional Arrays)
    11. Looping Over an Array, Backwards and Forwards
  11. 10. String()
    1. Conceptual Overview of Using the String() Object
    2. String() Parameters
    3. String() Properties and Methods
    4. String Object Instance Properties and Methods
  12. 11. Number()
    1. Conceptual Overview of Using the Number() Object
    2. Integers and Floating-Point Numbers
    3. Number() Parameters
    4. Number() Properties
    5. Number Object Instance Properties and Methods
  13. 12. Boolean()
    1. Conceptual Overview of Using the Boolean() Object
    2. Boolean() Parameters
    3. Boolean() Properties and Methods
    4. Boolean Object Instance Properties and Methods
    5. Non-Primitive False Boolean Objects Convert to true
    6. Certain Things Are false, Everything Else Is true
  14. 13. Working with Primitive String, Number, and Boolean Values
    1. Primitive/Literal Values Are Converted to Objects When Properties Are Accessed
    2. You Should Typically Use Primitive String, Number, and Boolean Values
  15. 14. Null
    1. Conceptual Overview of Using the null Value
    2. typeof Returns null Values as “object”
  16. 15. Undefined
    1. Conceptual Overview of the undefined Value
    2. JavaScript ECMAScript 3 Edition (and Later) Declares the undefined Variable in the Global Scope
  17. 16. Math Function
    1. Conceptual Overview of the Built-In Math Object
    2. Math Properties and Methods
    3. Math Is Not a Constructor Function
    4. Math Has Constants You Cannot Augment/Mutate
  18. A. Review
  19. B. Conclusion
  20. Index
  21. About the Author
  22. Colophon
  23. Copyright

Product information

  • Title: JavaScript Enlightenment
  • Author(s): Cody Lindley
  • Release date: December 2012
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781449342883