Object-Oriented JavaScript

Stoyan Stefanov

eBook: $23.99
Formats: PDF, PacktLib, ePub and Mobi formats
$14.39 save 40%!
Print book: $39.99
$35.99 save 10%!
Print + eBook bundle: $63.98
Includes free access to the book on PacktLib
$39.59 save 38%!
Free Shipping! UK, US, Europe and selected countries in Asia.
This book can also be purchased from:
Overview
Table of Contents
The Author
Reviews
Downloads
  • Learn to think in JavaScript, the language of the web browser
  • Object-oriented programming made accessible and understandable to web developers
  • Do it yourself: experiment with examples that can be used in your own scripts
  • Write better, more maintainable JavaScript code

Book Details

Language : English
Paperback : 356 pages [ 235mm x 191mm ]
Release Date : July 2008
ISBN : 1847194141
ISBN 13 : 978-1-847194-14-5
Author(s) : Stoyan Stefanov
Topics and Technologies : All Books, AJAX, Open Source, Web Development


Table of Contents

Preface
Chapter 1: Introduction
Chapter 2: Primitive Data Types, Arrays, Loops, and Conditions
Chapter 3: Functions
Chapter 4: Objects
Chapter 5: Prototype
Chapter 6: Inheritance
Chapter 7: The Browser Environment
Chapter 8: Coding and Design Patterns
Appendix A: Reserved Words
Appendix B: Built-in Functions
Appendix C: Built-in Objects
Appendix D: Regular Expressions
Index
  • Chapter 1: Introduction
    • A Bit of History
    • The Winds of Change
    • The Present
    • The Future
    • Object-Oriented Programming
      • Objects
      • Classes
      • Encapsulation
      • Aggregation
      • Inheritance
      • Polymorphism
    • OOP Summary
    • Setting up Your Training Environment
      • Getting the Tools You Need
    • Using the Firebug Console
    • Summary
  • Chapter 2: Primitive Data Types, Arrays, Loops, and Conditions
    • Variables
      • Variables are Case Sensitive
    • Operators
    • Primitive Data Types
      • Finding out the Value Type —the typeof Operator
      • Numbers
        • Octal and Hexadecimal Numbers
        • Exponent Literals
        • Infinity
        • NaN
      • Strings
        • String Conversions
        • Special Strings
      • Booleans
        • Logical Operators
        • Operator Precedence
        • Lazy Evaluation
        • Comparison
      • Undefined and null
    • Primitive Data Types Recap
    • Arrays
      • Adding/Updating Array Elements
      • Deleting Elements
      • Arrays of arrays
    • Conditions and Loops
      • Code Blocks
        • if Conditions
        • Checking if a Variable Exists
        • Alternative if Syntax
        • Switch
      • Loops
        • While Loops
        • Do-while loops
        • For Loops
        • For-in Loops
    • Comments
    • Summary
    • Exercises
  • Chapter 3: Functions
    • What is a Function?
      • Calling a Function
      • Parameters
    • Pre-defined Functions
      • parseInt()
      • parseFloat()
      • isNaN()
      • isFinite()
      • Encode/Decode URIs
      • eval()
      • A Bonus—the alert() Function
    • Scope of Variables
    • Functions are Data
      • Anonymous Functions
      • Callback Functions
      • Callback Examples
      • Self-invoking Functions
      • Inner (Private) Functions
      • Functions that Return Functions
      • Function, Rewrite Thyself!
    • Closures
      • Scope Chain
      • Lexical Scope
      • Breaking the Chain with a Closure
        • Closure #1
        • Closure #2
        • A Definition and Closure #3
        • Closures in a Loop
      • Getter/Setter
      • Iterator
    • Summary
    • Exercises
  • Chapter 4: Objects
    • From Arrays to Objects
      • Elements, Properties, Methods
      • Hashes, Associative Arrays
      • Accessing Object's Properties
      • Calling an Object's Methods
      • Altering Properties/Methods
      • Using this Value
      • Constructor Functions
      • The Global Object
      • constructor Property
      • instanceof Operator
      • Functions that Return Objects
      • Passing Objects
      • Comparing Objects
      • Objects in the Firebug Console
    • Built-in Objects
      • Object
      • Array
        • Interesting Array Methods
      • Function
        • Properties of the Function Objects
        • Methods of the Function Objects
        • The arguments Object Revisited
      • Boolean
      • Number
      • String
        • Interesting Methods of the String Objects
      • Math
      • Date
        • Methods to Work with Date Objects
      • RegExp
        • Properties of the RegExp Objects
        • Methods of the RegExp Objects
        • String Methods that Accept Regular Expressions as Parameters
        • search() and match()
        • replace()
        • Replace callbacks
        • split()
        • Passing a String When a regexp is Expected
    • Summary
    • Exercises
  • Chapter 5: Prototype
    • The prototype Property
      • Adding Methods and Properties Using the Prototype
      • Using the Prototype's Methods and Properties
      • Own Properties versus prototype Properties
      • Overwriting Prototype's Property with Own Property
        • Enumerating Properties
      • isPrototypeOf()
      • The Secret __proto__ Link
    • Augmenting Built-in Objects
      • Augmenting Built-in Objects—Discussion
      • Some Prototype gotchas
    • Summary
    • Exercises
  • Chapter 6: Inheritance
    • Prototype Chaining
      • Prototype Chaining Example
      • Moving Shared Properties to the Prototype
    • Inheriting the Prototype Only
      • A Temporary Constructor—new F()
    • Uber—Access to the Parent from a Child Object
    • Isolating the Inheritance Part into a Function
    • Copying Properties
    • Heads-up When Copying by Reference
    • Objects Inherit from Objects
    • Deep Copy
    • object()
    • Using a Mix of Prototypal Inheritance and Copying Properties
    • Multiple Inheritance
      • Mixins
    • Parasitic Inheritance
    • Borrowing a Constructor
      • Borrow a Constructor and Copy its Prototype
    • Summary
    • Case Study: Drawing Shapes
      • Analysis
      • Implementation
      • Testing
    • Exercises
  • Chapter 7: The Browser Environment
    • Including JavaScript in an HTML Page
    • BOM and DOM—An Overview
    • BOM
      • The window Object Revisited
      • window.navigator
      • Firebug as a Cheat Sheet
      • window.location
      • window.history
      • window.frames
      • window.screen
      • window.open()/close()
      • window.moveTo(), window.resizeTo()
      • window.alert(), window.prompt(), window.confirm()
      • window.setTimeout(), window.setInterval()
      • window.document
    • DOM
      • Core DOM and HTML DOM
      • Accessing DOM Nodes
        • The document Node
        • documentElement
        • Child Nodes
        • Attributes
        • Accessing the Content Inside a Tag
        • DOM Access Shortcuts
        • Siblings, Body, First, and Last Child
        • Walk the DOM
      • Modifying DOM Nodes
        • Modifying Styles
        • Fun with Forms
      • Creating New Nodes
        • DOM-only Method
        • cloneNode()
        • insertBefore()
      • Removing Nodes
      • HTML-Only DOM Objects
        • Primitive Ways to Access the Document
        • document.write()
        • Cookies, Title, Referrer, Domain
    • Events
      • Inline HTML Attributes
      • Element Properties
      • DOM Event Listeners
      • Capturing and Bubbling
      • Stop Propagation
      • Prevent Default Behavior
      • Cross-Browser Event Listeners
      • Types of Events
    • XMLHttpRequest
      • Send the Request
      • Process the Response
      • Creating XMLHttpRequest Objects in IE prior to version 7
      • A is for Asynchronous
      • X is for XML
      • An Example
    • Summary
    • Exercises
  • Chapter 8: Coding and Design Patterns
    • Coding Patterns
      • Separating Behavior
        • Content
        • Presentation
        • Behavior
        • Example of Separating Behavior
      • Namespaces
        • An Object as a Namespace
        • Namespaced Constructors
        • A namespace() Method
      • Init-Time Branching
      • Lazy Definition
      • Configuration Object
      • Private Properties and Methods
      • Privileged Methods
      • Private Functions as Public Methods
      • Self-Executing Functions
      • Chaining
      • JSON
    • Design Patterns
      • Singleton
      • Singleton 2
        • Global Variable
        • Property of the Constructor
        • In a Private Property
      • Factory
      • Decorator
        • Decorating a Christmas Tree
      • Observer
    • Summary
  • Appendix C: Built-in Objects
    • Object
      • Members of the Object Constructor
      • Members of the Objects Created by the Object Constructor
    • Array
      • Members of the Array Objects
    • Function
      • Members of the Function Objects
    • Boolean
    • Number
      • Members of the Number Constructor
      • Members of the Number Objects
    • String
      • Members of the String Constructor
      • Members of the String Objects
    • Date
      • Members of the Date Constructor
      • Members of the Date Objects
    • Math
      • Members of the Math Object
    • RegExp
      • Members of RegExp Objects
    • Error Objects
      • Members of the Error Objects

Stoyan Stefanov

Stoyan Stefanov is a Yahoo! web developer, Zend Certified Engineer, book author, and contributor to the international PHP community. He talks regularly about JavaScript, PHP, and other web development topics at conferences and his blog www.phpied.com and also runs a number of other sites, including JSPatterns.com – a site dedicated to exploring JavaScript patterns. Stoyan is the engineering lead of Yahoo's performance optimization tool 'YSlow', as well as other open-source tools and 'PEAR' libraries.

Sorry, we don't have any reviews for this title yet.

Sample chapters

You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

Find your book in our support section to find errata and to download code samples.

What you will learn from this book

  • Learn to think in JavaScript, the language of the web browser
  • The basics of object-oriented programming, and how they apply to JavaScript
  • Set up and use your training environment (Firebug)
  • Master data types, operators, and flow control statements
  • Understand functions: usage patterns, variable scope, and built-in functions
  • Closures demystified
  • Create and use objects
  • Understand and use prototypes
  • Reuse code with common patterns for inheritance
  • Understand and work with the BOM (Browser Object Model)
  • The DOM (Document Object Model) – accessing, modifying, adding, and deleting nodes
  • Build responsive web pages with AJAX
  • JSON (JavaScript Object Notation)
  • Listen and respond to browser events
  • Apply design patterns to solve common problems
  • Adopt coding patterns that unleash the unique power of the language
  • Make your programs cleaner, faster, and compatible with other programs and libraries
  • Achieve missing object-oriented features in JavaScript such as private properties and methods

Special Offers

PacktLib gives you access to this and 600+ other titles with an annual or monthly subscription.

Annual subscription:

$220.00 per annum

Monthly subscription:

$21.99 per month

Buy 2 eBooks
and Get 50% Off
+
Buy Object-Oriented JavaScript with Node Web Development and get 50% off both the eBooks.
Just add both the eBooks to your shopping cart and enter jvoonw in the 'Enter Promotion Code' field. Click 'Add Promotion Code' and the discount will be applied.
View Best Selling eBook offers

In Detail

Once listed in the "nice to have" sections of job postings, these days the knowledge of JavaScript is a deciding factor when it comes to hiring web developers. And rightly so. Where in the past we used to have the occasional few lines of JavaScript embedded in a web page, now we have advanced libraries and extensible architectures, powering the "fat-client", AJAX-type rich internet applications.

JavaScript is the language of the browser, but it's also heavily employed in many other environments: server-side programming, desktop applications, application extensions and widgets. It's a pretty good deal: you learn one language and then code all kinds of different applications. While this book has one chapter specifically dedicated to the web browser environment including DOM, events, and AJAX tutorials, the rest is applicable to all the other environments too. 

This book treats JavaScript as a serious object-oriented language, showing you how to build robust, maintainable, and powerful libraries and applications. Along the way, we cover many of the recent innovations such as AJAX, JSON, and interesting design and coding patterns. After reading this book, you'll be prepared to ace your JavaScript job interview and even impress with some bits that the interviewer maybe didn't know. You should read this book if you want to be able to take your JavaScript skills to a new level of sophistication.

Create scalable and reusable high-quality JavaScript applications and libraries using the concepts of object-oriented programming

Approach

Who this book is for

The book requires no prior knowledge of JavaScript and works from the ground up to give you a thorough grounding in this powerful language. If you do already know some JavaScript, you will find plenty of eye-openers as you discover just what the language can do.

This book takes a do-it-yourself approach when it comes to writing code, because the best way to really learn a programming language is by writing code. You are encouraged to type code into Firebug's console, see how it works and then tweak it and play around with it. There are practice questions at the end of each chapter to help review what you have learned.

Are there no books available that are right for you at the moment? How about signing up to our newsletter to keep up to date?
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Sort A-Z