1. Trang chủ
  2. » Công Nghệ Thông Tin

Object oriented javascript 3rd edition

537 107 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Cấu trúc

  • Copyright

  • Credits

  • About the Authors

  • About the Reviewer

  • www.PacktPub.com

  • Customer Feedback

  • Table of Contents

  • Preface

  • Chapter 1: Object-Oriented JavaScript

    • A bit of history

      • Browser wars and renaissance

      • The present

      • The future

    • ECMAScript 5

      • Strict mode in ES6

    • ECMAScript 6

      • Browser support for ES6

      • Babel

    • Object-oriented programming

      • Objects

      • Classes

      • Encapsulation

      • Aggregation

      • Inheritance

      • Polymorphism

    • OOP summary

    • Setting up your training environment

      • WebKit's web inspector

      • JavaScriptCore on a Mac

      • More consoles

    • 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

        • Binary Literals

        • Exponent literals

        • Infinity

        • NaN

          • Number.isNaN

          • Number.isInteger

      • Strings

        • String conversions

        • Special strings

        • String template literals

      • Booleans

        • Logical operators

        • Operator precedence

        • Lazy evaluation

        • Comparison

      • Undefined and null

      • Symbols

    • Primitive data types recap

    • Arrays

      • Adding/updating array elements

      • Deleting elements

      • Arrays of arrays

    • Conditions and loops

      • Code blocks

        • The if condition

        • The else clause

        • Checking if a variable exists

        • Alternative if syntax

        • Switch

          • Don't forget to break

      • Loops

        • While loops

        • Do-while loops

        • For loops

        • For…in loops

    • Comments

    • Exercises

    • Summary

  • Chapter 3: Functions

    • What is a function?

      • Calling a function

      • Parameters

    • Default parameters

    • Rest parameters

    • Spread operators

      • Predefined functions

        • parseInt()

        • parseFloat()

        • isNaN()

        • isFinite()

        • Encode/decode URIs

        • eval()

          • A bonus – the alert() function

    • Scope of variables

      • Variable hoisting

    • Block scope

    • Functions are data

      • Anonymous functions

      • Callback functions

        • Callback examples

      • Immediate functions

      • Inner (private) functions

      • Functions that return functions

      • Function, rewrite thyself!

    • Closures

      • Scope chain

      • Breaking the chain with a closure

        • Closure #1

        • Closure #2

        • A definition and closure #3

      • Closures in a loop

      • Getter and setter

      • Iterator

    • IIFE versus blocks

    • Arrow functions

    • Exercises

    • Summary

  • Chapter 4: Objects

    • From arrays to objects

      • Elements, properties, methods, and members

      • Hashes and associative arrays

      • Accessing an object's properties

      • Calling an object's methods

      • Altering properties/methods

      • Using the this value

      • Constructor functions

      • The global object

      • The constructor property

      • The instanceof operator

      • Functions that return objects

      • Passing objects

      • Comparing objects

      • Objects in the WebKit console

        • Logging using the console.log method

      • ES6 object literals

    • Object properties and attributes

    • ES6 object methods

      • [Copy properties using Object.assign]

        • Copy properties using Object.assign

        • Compare values with Object.is

    • Destructuring

    • Built-in objects

      • Object

      • Array

        • A few array methods

    • ES6 array methods

      • Array.from

      • Creating arrays using Array.of

      • Array.prototype methods

      • Function

        • Properties of function objects

        • Using the prototype property

        • Methods of function objects

        • Call and apply

        • The arguments object revisited

    • Lexical this in arrow functions

      • Inferring object types

      • Boolean

      • Number

      • String

        • A few methods of string objects

      • Math

      • Date

        • Methods to work with date objects

          • Calculating birthdays

      • RegExp

        • Properties of RegExp objects

        • Methods of RegExp objects

        • String methods that accept regular expressions as arguments

        • search() and match()

        • replace()

        • Replace callbacks

        • split()

        • Passing a string when a RegExp is expected

        • Error objects

    • Exercises

    • Summary

  • Chapter 5: ES6 Iterators and Generators

    • For…of loop

    • Iterators and iterables

      • Iterators

      • Iterables

    • Generators

      • Iterating over generators

    • Collections

      • Map

        • Iterating over maps

        • Converting maps to arrays

      • Set

      • WeakMap and WeakSet

    • Summary

  • Chapter 6: Prototype

    • The prototype property

      • Adding methods and properties using the prototype

    • Using the prototype's methods and properties

      • Own properties versus prototype properties

      • Overwriting a prototype's property with an own property

        • Enumerating properties

      • Using isPrototypeOf() method

      • The secret __proto__ link

    • Augmenting built-in objects

      • Augmenting built-in objects – discussion

      • Prototype gotchas

    • Exercises

    • Summary

  • Chapter 7: 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

    • Using object() method

    • Using a mix of prototypal inheritance and copying properties

    • Multiple inheritance

      • Mixins

    • Parasitic inheritance

    • Borrowing a constructor

      • Borrowing a constructor and copying its prototype

    • Case study – drawing shapes

      • Analysis

      • Implementation

      • Testing

    • Exercises

    • Summary

  • Chapter 8: Classes and Modules

    • Defining classes

      • Constructor

      • Prototype methods

      • Static methods

      • Static properties

      • Generator methods

    • Subclassing

      • Mixins

    • Modules

      • Export lists

    • Summary

  • Chapter 9: Promises and Proxies

    • [Asynchronous programming model]

      • Asynchronous programming model

    • JavaScript call stack

      • Message queue

      • Event loop

      • Timers

        • Run to completion

        • Events

        • Callbacks

    • Promises

      • Creating promises

        • Promise.all()

      • Metaprogramming and proxies

      • Proxy

      • Function traps

    • Summary

  • Chapter 10: The Browser Environment

    • Including JavaScript in an HTML page

    • BOM and DOM – an overview

    • BOM

      • The window object revisited

      • Using window.navigator property

      • Your console is a cheat sheet

      • Using window.location property

      • Using window.history property

      • using window.frames property

      • Using window.screen property

      • window.open()/close() method

      • window.moveTo() and window.resizeTo() methods

      • window.alert(), window.prompt(), and window.confirm() methods

      • Using window.setTimeout() and window.setInterval() methods

      • window.document property

    • 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

        • Using cloneNode() method

        • Using insertBefore() method

      • Removing nodes

      • HTML – only DOM objects

        • Primitive ways to access the document

        • Using document.write() method

        • Cookies, title, referrer, and 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

      • Sending the request

      • Processing the response

      • Creating XMLHttpRequest objects in IE prior to Version 7

      • A is for Asynchronous

      • X is for XML

      • An example

    • Exercises

    • Summary

  • Chapter 11: Coding and Design Patterns

    • Coding patterns

      • Separating behavior

        • Content

        • Presentation

        • Behavior

          • Example of separating behavior

        • Asynchronous JavaScript loading

      • 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

      • Immediate functions

      • Modules

      • Chaining

      • JSON

      • Higher order functions

    • Design patterns

      • Singleton pattern

      • Singleton 2 pattern

        • Global variable

        • Property of the constructor

        • In a private property

      • Factory pattern

      • Decorator pattern

        • Decorating a christmas tree

      • Observer pattern

    • Summary

  • Chapter 12: Testing and Debugging

    • Unit testing

      • Test Driven Development

      • Behavior Driven Development

      • Mocha, Chai and Sinon

    • JavaScript debugging

      • Syntax errors

        • Using strict

      • Runtime exceptions

        • Console.log and asserts

        • Chrome Developer Tools

    • Summary

  • Chapter 13: Reactive Programming and React

    • Reactive programming

      • Why should you consider reactive programming?

    • React

    • Virtual DOM

    • Installing and running react

      • Components and props

      • State

      • Life cycle events

    • Summary

  • Appendix A: Reserved Words

    • Keywords

    • ES6 reserved words

      • Future reserved words

    • Previously reserved words

  • Appendix B: Built-in Functions

  • Appendix C: Built-in Objects

    • Object

      • Members of the Object constructor

      • The Object.prototype members

      • ECMAScript 5 additions to objects

    • ES6 addition to objects

      • Property shorthand

      • Computed property names

      • Object.assign

    • Array

      • The Array.prototype members

      • ECMAScript 5 additions to Array

      • ES6 addition to arrays

    • Function

      • The Function.prototype members

      • ECMAScript 5 additions to a Function

      • ECMAScript 6 additions to a Function

    • Boolean

    • Number

      • Members of the Number constructor

      • The Number.prototype members

    • String

      • Members of the String constructor

      • The String.prototype members

      • ECMAScript 5 additions to String

      • ECMAScript 6 additions to String

    • Date

      • Members of the Date constructor

      • The Date.prototype members

      • ECMAScript 5 additions to Date

    • Math

      • Members of the Math object

    • RegExp

      • The RegExp.prototype members

    • Error objects

      • The Error.prototype members

    • JSON

      • Members of the JSON object

  • Appendix D: Regular Expressions

  • Appendix E: Answers to Exercise Questions

    • Chapter 2, Primitive Data Types, Arrays, Loops, and Conditions

      • Exercises

    • Chapter 3, Functions

      • Exercises

    • Chapter 4, Objects

      • Exercises

    • Chapter 5, Prototype

      • Exercises

    • Chapter 6, Inheritance

      • Exercises

    • Chapter 7, The Browser Environment

      • Exercises

  • Index

Nội dung

Object-Oriented JavaScript Third Edition Learn everything you need to know about object-oriented JavaScript with this comprehensive guide Enter the world of cutting-edge development! Ved Antani Stoyan Stefanov BIRMINGHAM - MUMBAI Object-Oriented JavaScript Third Edition Copyright © 2017 Packt Publishing All rights reserved No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews Every effort has been made in the preparation of this book to ensure the accuracy of the information presented However, the information contained in this book is sold without warranty, either express or implied Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals However, Packt Publishing cannot guarantee the accuracy of this information First published: July 2008 Second edition: July 2013 Third edition: January 2017 Production reference: 1050117 Published by Packt Publishing Ltd Livery Place 35 Livery Street Birmingham B3 2PB, UK ISBN 978-1-78588-056-8 www.packtpub.com Credits Authors Copy Editor Ved Antani Zainab Bootwala Stoyan Stefanov Reviewer Project Coordinator Mohamed Sanaulla Ritika Manoj Commissioning Editor Proofreader Wilson Dsouza Safis Editing Acquisition Editor Indexer Denim Pinto Rekha Nair Content Development Editor Graphics Arun Nadar Jason Monteiro Technical Editor Production Coordinator Abhishek Sharma Arvindkumar Gupta   About the Authors Ved Antani has been building scalable server and mobile platforms using JavaScript, Go, and Java since 2005 He is an associate vice president at Myntra and has previously worked at Electronic Arts and Oracle He is an avid reader and author on several subjects He has studied computer science and currently lives in Bangalore, India Ved is passionate about classical music and loves to spend time with his son Writing this book required a significant investment of my time, and I would like to thank my parents and family for their support and encouragement during those long days and weekends when I was practically invisible Stoyan Stefanov is a Facebook engineer, author, and speaker He talks regularly about web development topics at conferences, and his blog, www.phpied.com He also runs a number of other sites, including JSPatterns.com - a site dedicated to exploring JavaScript patterns Previously at Yahoo!, Stoyan was the architect of YSlow 2.0 and creator of the image optimization tool, Smush.it A "citizen of the world", Stoyan was born and raised in Bulgaria, but is also a Canadian citizen, currently residing in Los Angeles, California In his offline moments, he enjoys playing the guitar, taking flying lessons, and spending time at the Santa Monica beaches with his family I'd like to dedicate this book to my wife, Eva, and my daughters, Zlatina and Nathalie Thank you for your patience, support, and encouragement About the Reviewer Mohamed Sanaulla is a software developer with more than years of experience in developing enterprise applications and Java-based back-end solutions for e-commerce applications His interests include Enterprise software development, refactoring and redesigning applications, designing and implementing RESTful web services, troubleshooting Java applications for performance issues, and TDD He has strong expertise in Java-based application development, ADF (JSF-based JavaEE web framework), SQL, PL/SQL, JUnit, designing RESTful services, Spring, Struts, Elasticsearch, and MongoDB He is also a Sun Certified Java Programmer for the Java platform He is a moderator for JavaRanch.com He likes to share findings on his blog (http ://sanaulla.info) www.PacktPub.com For support files and downloads related to your book, please visit www.PacktPub.com Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy Get in touch with us at service@packtpub.com for more details At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks https://www.packtpub.com/mapt Get the most in-demand software skills with Mapt Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career Why subscribe? Fully searchable across every book published by Packt Copy and paste, print, and bookmark content On demand and accessible via a web browser Customer Feedback Thank you for purchasing this Packt book We take our commitment to improving our content and products to meet your needs seriously that's why your feedback is so valuable Whatever your feelings about your purchase, please consider leaving a review on this book's Amazon page Not only will this help us, more importantly it will also help others in the community to make an informed decision about the resources that they invest in to learn You can also review for us on a regular basis by joining our reviewers' club If you're interested in joining, or would like to learn more about the benefits we offer, please contact us: customerreviews@packtpub.com Table of Contents Preface Chapter 1: Object-Oriented JavaScript A bit of history Browser wars and renaissance The present The future ECMAScript Strict mode in ES6 ECMAScript Browser support for ES6 Babel Object-oriented programming Objects Classes Encapsulation Aggregation Inheritance Polymorphism OOP summary Setting up your training environment WebKit's web inspector JavaScriptCore on a Mac More consoles 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 Binary Literals Exponent literals 10 11 12 12 13 13 15 16 16 17 18 18 19 19 20 21 22 24 26 27 27 29 30 33 34 35 35 36 37 Infinity NaN Number.isNaN Number.isInteger Strings String conversions Special strings String template literals Booleans Logical operators Operator precedence Lazy evaluation Comparison Undefined and null Symbols Primitive data types recap Arrays Adding/updating array elements Deleting elements Arrays of arrays Conditions and loops Code blocks The if condition The else clause Checking if a variable exists Alternative if syntax Switch Don't forget to break Loops While loops Do-while loops For loops For…in loops Comments Exercises Summary Chapter 3: Functions 38 39 40 40 41 42 43 44 46 46 48 49 50 52 53 54 55 56 57 57 59 59 60 60 61 63 64 65 65 66 67 67 70 71 71 72 73 What is a function? Calling a function Parameters Default parameters Rest parameters Spread operators 74 74 75 77 78 79 [ ii ] .. .Object- Oriented JavaScript Third Edition Learn everything you need to know about object- oriented JavaScript with this comprehensive guide Enter... that return objects Passing objects Comparing objects Objects in the WebKit console Logging using the console.log method ES6 object literals Object properties and attributes ES6 object methods... Built-in Objects 427 430 Object Members of the Object constructor The Object. prototype members ECMAScript additions to objects ES6 addition to objects Property shorthand Computed property names Object. assign

Ngày đăng: 04/03/2019, 13:43

TỪ KHÓA LIÊN QUAN