0%

Book Description

Learn everything you need to know about object-oriented JavaScript with this comprehensive guide. Enter the world of cutting-edge development!

About This Book

  • This book has been updated to cover all the new object-oriented features introduced in ECMAScript 6
  • It makes object-oriented programming accessible and understandable to web developers
  • Write better and more maintainable JavaScript code while exploring interactive examples that can be used in your own scripts

Who This Book Is For

This book is ideal for new to intermediate JavaScript developers who want to prepare themselves for web development problems solved by object-oriented JavaScript!

What You Will Learn

  • Apply the basics of object-oriented programming in the JavaScript environment
  • Use a JavaScript Console with complete mastery
  • Make your programs cleaner, faster, and compatible with other programs and libraries
  • Get familiar with Iterators and Generators, the new features added in ES6
  • Find out about ECMAScript 6's Arrow functions, and make them your own
  • Understand objects in Google Chrome developer tools and how to use them
  • Use a mix of prototypal inheritance and copying properties in your workflow
  • Apply reactive programming techniques while coding in JavaScript

In Detail

JavaScript is an object-oriented programming language that is used for website development. Web pages developed today currently follow a paradigm that has three clearly distinguishable parts: content (HTML), presentation (CSS), and behavior (JavaScript). JavaScript is one important pillar in this paradigm, and is responsible for the running of the web pages.

This book will take your JavaScript skills to a new level of sophistication and get you prepared for your journey through professional web development. Updated for ES6, this book covers everything you will need to unleash the power of object-oriented programming in JavaScript while building professional web applications. The book begins with the basics of object-oriented programming in JavaScript and then gradually progresses to cover functions, objects, and prototypes, and how these concepts can be used to make your programs cleaner, more maintainable, faster, and compatible with other programs/libraries.

By the end of the book, you will have learned how to incorporate object-oriented programming in your web development workflow to build professional JavaScript applications.

Style and approach

Filled with practical instructions, the book shows you how to implement object-oriented features of JavaScript in the real world. The to-the-point nature of the book will benefit developers who are looking for a fast-paced guide to learn object-oriented JavaScript.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Object-Oriented JavaScript - Third Edition
    1. Object-Oriented JavaScript - Third Edition
    2. Credits
    3. About the Authors
    4. About the Reviewer
    5. www.PacktPub.com
      1. Why subscribe?
    6. Customer Feedback
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Errata
        2. Piracy
        3. Questions
    8. 1. Object-Oriented JavaScript
      1. A bit of history
        1. Browser wars and renaissance
        2. The present
        3. The future
      2. ECMAScript 5
        1. Strict mode in ES6
      3. ECMAScript 6
        1. Browser support for ES6
        2. Babel
      4. Object-oriented programming
        1. Objects
        2. Classes
        3. Encapsulation
        4. Aggregation
        5. Inheritance
        6. Polymorphism
      5. OOP summary
      6. Setting up your training environment
        1. WebKit's web inspector
        2. JavaScriptCore on a Mac
        3. More consoles
      7. Summary
    9. 2. Primitive Data Types, Arrays, Loops, and Conditions
      1. Variables
        1. Variables are case sensitive
      2. Operators
      3. Primitive data types
        1. Finding out the value type - the typeof operator
        2. Numbers
          1. Octal and hexadecimal numbers
          2. Binary Literals
          3. Exponent literals
          4. Infinity
          5. NaN
            1. Number.isNaN
            2. Number.isInteger
        3. Strings
          1. String conversions
          2. Special strings
          3. String template literals
        4. Booleans
          1. Logical operators
          2. Operator precedence
          3. Lazy evaluation
          4. Comparison
        5. Undefined and null
        6. Symbols
      4. Primitive data types recap
      5. Arrays
        1. Adding/updating array elements
        2. Deleting elements
        3. Arrays of arrays
      6. Conditions and loops
        1. Code blocks
          1. The if condition
          2. The else clause
          3. Checking if a variable exists
          4. Alternative if syntax
          5. Switch
            1. Don't forget to break
        2. Loops
          1. While loops
          2. Do-while loops
          3. For loops
          4. For...in loops
      7. Comments
      8. Exercises
      9. Summary
    10. 3. Functions
      1. What is a function?
        1. Calling a function
        2. Parameters
      2. Default parameters
      3. Rest parameters
      4. Spread operators
        1. Predefined functions
          1. parseInt()
          2. parseFloat()
          3. isNaN()
          4. isFinite()
          5. Encode/decode URIs
          6. eval()
            1. A bonus - the alert() function
      5. Scope of variables
        1. Variable hoisting
      6. Block scope
      7. Functions are data
        1. Anonymous functions
        2. Callback functions
          1. Callback examples
        3. Immediate functions
        4. Inner (private) functions
        5. Functions that return functions
        6. Function, rewrite thyself!
      8. Closures
        1. Scope chain
        2. Breaking the chain with a closure
          1. Closure #1
          2. Closure #2
          3. A definition and closure #3
        3. Closures in a loop
        4. Getter and setter
        5. Iterator
      9. IIFE versus blocks
      10. Arrow functions
      11. Exercises
      12. Summary
    11. 4. Objects
      1. From arrays to objects
        1. Elements, properties, methods, and members
        2. Hashes and associative arrays
        3. Accessing an object's properties
        4. Calling an object's methods
        5. Altering properties/methods
        6. Using the this value
        7. Constructor functions
        8. The global object
        9. The constructor property
        10. The instanceof operator
        11. Functions that return objects
        12. Passing objects
        13. Comparing objects
        14. Objects in the WebKit console
          1. Logging using the console.log method
        15. ES6 object literals
      2. Object properties and attributes
      3. ES6 object methods
        1. Copy properties using Object.assign
        2. Compare values with Object.is
      4. Destructuring
      5. Built-in objects
        1. Object
        2. Array
          1. A few array methods
      6. ES6 array methods
        1. Array.from
        2. Creating arrays using Array.of
        3. Array.prototype methods
        4. Function
          1. Properties of function objects
          2. Using the prototype property
          3. Methods of function objects
          4. Call and apply
          5. The arguments object revisited
      7. Lexical this in arrow functions
        1. Inferring object types
        2. Boolean
        3. Number
        4. String
          1. A few methods of string objects
        5. Math
        6. Date
          1. Methods to work with date objects
            1. Calculating birthdays
        7. RegExp
          1. Properties of RegExp objects
          2. Methods of RegExp objects
          3. String methods that accept regular expressions as arguments
          4. search() and match()
          5. replace()
          6. Replace callbacks
          7. split()
          8. Passing a string when a RegExp is expected
          9. Error objects
      8. Exercises
      9. Summary
    12. 5. ES6 Iterators and Generators
      1. For...of loop
      2. Iterators and iterables
        1. Iterators
        2. Iterables
      3. Generators
        1. Iterating over generators
      4. Collections
        1. Map
          1. Iterating over maps
          2. Converting maps to arrays
        2. Set
        3. WeakMap and WeakSet
      5. Summary
    13. 6. Prototype
      1. The prototype property
        1. Adding methods and properties using the prototype
      2. Using the prototype's methods and properties
        1. Own properties versus prototype properties
        2. Overwriting a prototype's property with an own property
          1. Enumerating properties
        3. Using isPrototypeOf() method
        4. The secret __proto__ link
      3. Augmenting built-in objects
        1. Augmenting built-in objects - discussion
        2. Prototype gotchas
      4. Exercises
      5. Summary
    14. 7. Inheritance
      1. Prototype chaining
        1. Prototype chaining example
        2. Moving shared properties to the prototype
      2. Inheriting the prototype only
        1. A temporary constructor - new F()
      3. Uber - access to the parent from a child object
      4. Isolating the inheritance part into a function
      5. Copying properties
      6. Heads-up when copying by reference
      7. Objects inherit from objects
      8. Deep copy
      9. Using object() method
      10. Using a mix of prototypal inheritance and copying properties
      11. Multiple inheritance
        1. Mixins
      12. Parasitic inheritance
      13. Borrowing a constructor
        1. Borrowing a constructor and copying its prototype
      14. Case study - drawing shapes
        1. Analysis
        2. Implementation
        3. Testing
      15. Exercises
      16. Summary
    15. 8. Classes and Modules
      1. Defining classes
        1. Constructor
        2. Prototype methods
        3. Static methods
        4. Static properties
        5. Generator methods
      2. Subclassing
        1. Mixins
      3. Modules
        1. Export lists
      4. Summary
    16. 9. Promises and Proxies
      1. Asynchronous programming model
      2. JavaScript call stack
        1. Message queue
        2. Event loop
        3. Timers
          1. Run to completion
          2. Events
          3. Callbacks
      3. Promises
        1. Creating promises
          1. Promise.all()
        2. Metaprogramming and proxies
        3. Proxy
        4. Function traps
      4. Summary
    17. 10. The Browser Environment
      1. Including JavaScript in an HTML page
      2. BOM and DOM - an overview
      3. BOM
        1. The window object revisited
        2. Using window.navigator property
        3. Your console is a cheat sheet
        4. Using window.location property
        5. Using window.history property
        6. using window.frames property
        7. Using window.screen property
        8. window.open()/close() method
        9. window.moveTo() and window.resizeTo() methods
        10. window.alert(), window.prompt(), and window.confirm() methods
        11. Using window.setTimeout() and window.setInterval() methods
        12. window.document property
      4. DOM
        1. Core DOM and HTML DOM
        2. Accessing DOM nodes
          1. The document node
          2. documentElement
          3. Child nodes
          4. Attributes
          5. Accessing the content inside a tag
          6. DOM access shortcuts
          7. Siblings, body, first, and last child
          8. Walk the DOM
        3. Modifying DOM nodes
          1. Modifying styles
          2. Fun with forms
        4. Creating new nodes
          1. DOM-only method
          2. Using cloneNode() method
          3. Using insertBefore() method
        5. Removing nodes
        6. HTML - only DOM objects
          1. Primitive ways to access the document
          2. Using document.write() method
          3. Cookies, title, referrer, and domain
      5. Events
        1. Inline HTML attributes
        2. Element Properties
        3. DOM event listeners
        4. Capturing and bubbling
        5. Stop propagation
        6. Prevent default behavior
        7. Cross-browser event listeners
        8. Types of events
      6. XMLHttpRequest
        1. Sending the request
        2. Processing the response
        3. Creating XMLHttpRequest objects in IE prior to Version 7
        4. A is for Asynchronous
        5. X is for XML
        6. An example
      7. Exercises
      8. Summary
    18. 11. Coding and Design Patterns
      1. Coding patterns
        1. Separating behavior
          1. Content
          2. Presentation
          3. Behavior
            1. Example of separating behavior
          4. Asynchronous JavaScript loading
        2. Namespaces
          1. An Object as a namespace
          2. Namespaced constructors
          3. A namespace() method
        3. Init-time branching
        4. Lazy definition
        5. Configuration object
        6. Private properties and methods
        7. Privileged methods
        8. Private functions as public methods
        9. Immediate functions
        10. Modules
        11. Chaining
        12. JSON
        13. Higher order functions
      2. Design patterns
        1. Singleton pattern
        2. Singleton 2 pattern
          1. Global variable
          2. Property of the constructor
          3. In a private property
        3. Factory pattern
        4. Decorator pattern
          1. Decorating a christmas tree
        5. Observer pattern
      3. Summary
    19. 12. Testing and Debugging
      1. Unit testing
        1. Test Driven Development
        2. Behavior Driven Development
        3. Mocha, Chai and Sinon
      2. JavaScript debugging
        1. Syntax errors
          1. Using strict
        2. Runtime exceptions
          1. Console.log and asserts
          2. Chrome Developer Tools
      3. Summary
    20. 13. Reactive Programming and React
      1. Reactive programming
        1. Why should you consider reactive programming?
      2. React
      3. Virtual DOM
      4. Installing and running react
        1. Components and props
        2. State
        3. Life cycle events
      5. Summary
    21. A. Reserved Words
      1. Keywords
      2. ES6 reserved words
        1. Future reserved words
      3. Previously reserved words
    22. B. Built-in Functions
    23. C. Built-in Objects
      1. Object
        1. Members of the Object constructor
        2. The Object.prototype members
        3. ECMAScript 5 additions to objects
      2. ES6 addition to objects
        1. Property shorthand
        2. Computed property names
        3. Object.assign
      3. Array
        1. The Array.prototype members
        2. ECMAScript 5 additions to Array
        3. ES6 addition to arrays
      4. Function
        1. The Function.prototype members
        2. ECMAScript 5 additions to a Function
        3. ECMAScript 6 additions to a Function
      5. Boolean
      6. Number
        1. Members of the Number constructor
        2. The Number.prototype members
      7. String
        1. Members of the String constructor
        2. The String.prototype members
        3. ECMAScript 5 additions to String
        4. ECMAScript 6 additions to String
      8. Date
        1. Members of the Date constructor
        2. The Date.prototype members
        3. ECMAScript 5 additions to Date
      9. Math
        1. Members of the Math object
      10. RegExp
        1. The RegExp.prototype members
      11. Error objects
        1. The Error.prototype members
      12. JSON
        1. Members of the JSON object
    24. D. Regular Expressions
    25. E. Answers to Exercise Questions
      1. Chapter 2, Primitive Data Types, Arrays, Loops, and Conditions
        1. Exercises
      2. Chapter 3, Functions
        1. Exercises
      3. Chapter 4, Objects
        1. Exercises
      4. Chapter 5, Prototype
        1. Exercises
      5. Chapter 6, Inheritance
        1. Exercises
      6. Chapter 7, The Browser Environment
        1. Exercises
3.128.198.21