JJavaScriptavaScript

2y ago
51 Views
16 Downloads
1.69 MB
51 Pages
Last View : 7d ago
Last Download : 3m ago
Upload by : Tripp Mcmullen
Transcription

JavaScript20 Lessons to Successful Web Development

About the AuthorRobin Nixon is a prolific author on programming and web development (as well aspsychology and motivation), with his books having been translated into numerousforeign languages—frequently topping the US and international computer book charts.He has worked with computers and technology for all his life, and began writing aboutthe subject about 35 years ago.He has authored hundreds of articles and over two dozen books, and is a popularvideo and online instructor, with thousands of students taking his courses. Robinis also an accomplished programmer, developer, and entrepreneur, with severalsuccessful Internet startups to his name, from which he has learned a wealth ofprogramming hints and tips, which he enjoys passing on in his expanding range ofweb development books, including the following titles: CSS & CSS3: 20 Lessons to Successful Web Development (McGraw-Hill Education, 2015)HTML5: 20 Lessons to Successful Web Development (McGraw-Hill Education, 2015)PHP: 20 Lessons to Successful Web Development (McGraw-Hill Education, 2015)Learning PHP, MySQL, JavaScript, CSS & HTML5 (O’Reilly, 2014)Web Developer’s Cookbook (McGraw-Hill Education, 2012)HTML5 for iOS and Android (McGraw-Hill Education, 2010)About the Technical EditorAlbert Wiersch has been writing software since the Commodore VIC-20 andCommodore 64 days in the early 1980s. He holds a Bachelor of Science degree inComputer Science Engineering and an MBA from the University of Texas at Arlington.Albert currently develops and sells software that helps web developers, educators,students, businesses, and government agencies check their HTML and CSS documentsand their websites for quality problems, including many SEO (search engine optimization),mobility, and accessibility issues, with discounts made available to students. His websiteis at HTMLValidator.com.

JavaScript20 Lessons to Successful Web DevelopmentRobin NixonMilanNew York Chicago San FranciscoAthens London Madrid Mexico CityNew Delhi Singapore Sydney Toronto

Copyright 2015 by McGraw-Hill Education. All rights reserved. Except as permitted under the United States Copyright Act of 1976,no part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system,without the prior written permission of the publisher, with the exception that the program listings may be entered, stored, and executed in acomputer system, but they may not be reproduced for publication.ISBN: 978-0-07-184157-3MHID: 0-07-184157-1The material in this eBook also appears in the print version of this title: ISBN: 978-0-07-184158-0,MHID: 0-07-184158-X.eBook conversion by codeMantraVersion 1.0All trademarks are trademarks of their respective owners. Rather than put a trademark symbol after every occurrence of a trademarkedname, we use names in an editorial fashion only, and to the benefit of the trademark owner, with no intention of infringement of thetrademark. Where such designations appear in this book, they have been printed with initial caps.McGraw-Hill Education eBooks are available at special quantity discounts to use as premiums and sales promotions or for use in corporatetraining programs. To contact a representative, please visit the Contact Us page at www.mhprofessional.com.Information has been obtained by McGraw-Hill Education from sources believed to be reliable. However, because of the possibility ofhuman or mechanical error by our sources, McGraw-Hill Education, or others, McGraw-Hill Education does not guarantee the accuracy,adequacy, or completeness of any information and is not responsible for any errors or omissions or the results obtained from the use ofsuch information.TERMS OF USEThis is a copyrighted work and McGraw-Hill Education and its licensors reserve all rights in and to the work. Use of this work is subjectto these terms. Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one copy of the work, you maynot decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, transmit, distribute, disseminate,sell, publish or sublicense the work or any part of it without McGraw-Hill Education’s prior consent. You may use the work for your ownnoncommercial and personal use; any other use of the work is strictly prohibited. Your right to use the work may be terminated if you failto comply with these terms.THE WORK IS PROVIDED “AS IS.” McGRAW-HILL EDUCATION AND ITS LICENSORS MAKE NO GUARANTEES ORWARRANTIES AS TO THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED FROMUSING THE WORK, INCLUDING ANY INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINKOR OTHERWISE, AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITEDTO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. McGraw-Hill Education andits licensors do not warrant or guarantee that the functions contained in the work will meet your requirements or that its operation will beuninterrupted or error free. Neither McGraw-Hill Education nor its licensors shall be liable to you or anyone else for any inaccuracy, erroror omission, regardless of cause, in the work or for any damages resulting therefrom. McGraw-Hill Education has no responsibility for thecontent of any information accessed through the work. Under no circumstances shall McGraw-Hill Education and/or its licensors be liablefor any indirect, incidental, special, punitive, consequential or similar damages that result from the use of or inability to use the work, evenif any of them has been advised of the possibility of such damages. This limitation of liability shall apply to any claim or cause whatsoeverwhether such claim or cause arises in contract, tort or otherwise.

To Julie

This page intentionally left blank

Contents at a GlancePART IPART IIPART IIIJavaScript Basics1Introduction to JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2Incorporating JavaScript into a Web Page . . . . . . . . . . . . . . . . . . . . . . . .3Working with Arithmetic Operators and Functions . . . . . . . . . . . . . . . . .4Applying Comparison and Logical Operators . . . . . . . . . . . . . . . . . . . . .5Creating JavaScript Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6Accessing Multidimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7Calling Array Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3112331414961Advanced JavaScript8Pushing to and Popping from Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . .9Advanced Array Manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10 Controlling Program Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11 Looping Sections of Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12 Writing Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13 Manipulating JavaScript Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14 Handling Errors and Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . .15 Interacting with the Document Object Model . . . . . . . . . . . . . . . . . . . . . .16 Inserting Inline JavaScript and Events . . . . . . . . . . . . . . . . . . . . . . . . . . .17 Controlling Cookies and Local Storage . . . . . . . . . . . . . . . . . . . . . . . . . . .18 Working with Different Browsers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19 Implementing Interrupts and Timeouts . . . . . . . . . . . . . . . . . . . . . . . . . .20 Using Ajax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . swers to the Self-Test Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205BCommon JavaScript Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229vii

This page intentionally left blank

ContentsAcknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviiIntroduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xixPART IJavaScript BasicsLESSON 1Introduction to JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . .In the Beginning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .In-browser Scripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Info for Programmers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .All About Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Why You Need to Know JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Self-Test Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .LESSON 2Incorporating JavaScript into a Web Page . . . . . . . . . . . . . . . . .Using Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using Semicolons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Where to Place the JavaScript Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .In the Document Head . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .In the Document Body . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Including JavaScript Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .JavaScript Language Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Case Sensitivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Whitespace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Variable Naming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .String Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Variable Typing and Casting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Self-Test Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3456679911111213131314151515161717192121ix

xContentsLESSON 3Working with Arithmetic Operators and Functions . . . . . . . . . . .Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Pre-Incrementing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Post-Incrementing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Pre- and Post-Decrementing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Arithmetic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Assignment Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Self-Test Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .LESSON 4Applying Comparison and Logical Operators . . . . . . . . . . . . . . .Comparison Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .The Ternary Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Bitwise Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Operator Precedence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Operator Associativity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .The with Keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Self-Test Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .LESSON 5Creating JavaScript Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . .Array Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Creating an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Creating an Array of Specific Length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Assigning Values to an Array Element . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Retrieving Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using Array Elements as Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Other Ways of Creating Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using Associative Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Keys, Values, and Hash Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Other Ways of Creating an Associative Array . . . . . . . . . . . . . . . . . . . . . . . .Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Self-Test Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .LESSON 6Accessing Multidimensional Arrays.Creating a Two-Dimensional Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Accessing a Two-Dimensional Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .A More Practical Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Multidimensional Associative Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Creating the Multidimensional Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Accessing the Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Self-Test Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34445454646464848495052545657596060

ContentsLESSON 7Calling Array Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using for( in ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using concat() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .An Alternative to concat() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using join() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .The forEach() Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .The map() Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Self-Test Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .PART IIxi616162646465666666Advanced JavaScriptLESSON 8Pushing to and Popping from Arrays . . . . . . . . . . . . . . . . . . . . .Using push() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using pop() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using push() and pop() Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using reverse() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using Stacks and Buffers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Buffering Using an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Creating a Function for Pushing to the Top . . . . . . . . . . . . . . . . . . . . . . . . .Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Self-Test Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .LESSON 9Advanced Array Manipulation.Using sort() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Tailoring the sort() Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Sorting Numerically . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Reversing a Sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using splice() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Removing Elements from an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Inserting Elements into an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Advanced Array Splicing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Self-Test Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .LESSON 10Controlling Program Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . .The if() Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Omitting the Braces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Positioning of Braces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .The else Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .The else if() Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .The switch() Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using the break Keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using the default Keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Allowing Fall-Through . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Self-Test Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19193949696979898

xiiContentsLESSON 11Looping Sections of Code.Using while() Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .The Example in Detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using do . while() Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .The Example in Detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using for() Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .The Example in Detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using for(. in .) Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Breaking Out of a Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .The continue Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Self-Test Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .LESSON 12Writing Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .The return Keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Passing Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Accessing Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using the arguments Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using the this Keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Anonymous Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Global and Local Variable Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using Local Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Global Naming Convention . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Self-Test Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .LESSON 13Manipulating JavaScript Objects.Declaring a Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Creating an Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Accessing Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .The prototype Keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Extending JavaScript Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Self-Test Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .LESSON 14Handling Errors and Regular Expressions . . . . . . . . . . . . . . . .Using onerror . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Limiting the Scope of onerror . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using try catch() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Ignoring the Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using test() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using replace() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Replacing Globally . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Fuzzy Matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129129131131132133133134135135

ContentsMatching Any Character . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Not Matching a Character . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Self-Test Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .LESSON 15Interacting with the Document Object Model.The DOM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Accessing the DOM from JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using the getElementById() Function . . . . . . . . . . . . . . . . . . . . . . . . . .The Simpler O() Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .The Partner S() Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Accessing Multiple Elements by Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using the C() Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .The Difference Between Propertiesin CSS and JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Summary of the Three Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Some Common Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Other Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Self-Test Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .LESSON 16Inserting Inline JavaScript and Events . . . . . . . . . . . . . . . . .Inline JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Another Instance of this . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Non-inline Event Attaching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Attaching to Other Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Adding New Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Removing Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Alternatives to Adding and Removing Elements . . . . . . . . . . . . . . . . . . . . .Controlling HTML5 Media . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Self-Test Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .LESSON 17Controlling Cookies and Local Storage.Using Cookies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Setting a Cookie . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Reading a Cookie . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Deleting a Cookie . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Using Local Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Removing and Clearing Local Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Self-Test Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .LESSON 18Working with Different Browsers . . . . . . . . . . . . . . . . . . . . 6167168169171171171173The User Agent String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174The GetBrowser() Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174

xivContentsThe Query String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .The GetQueryString() Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Self-Test Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .LESSON 19Implementing Interrupts and Timeouts.Using Interrupts . . . . . . . . . . . . . . . . . .

PHP: 20 Lessons to Successful Web Development (McGraw-Hill Education, 2015) Learning PHP, MySQL, JavaScript, CSS & HTML5 (O’Reilly, 2014) Web Developer’s Cookbook (McGraw-Hill Education, 2012) HTML5 for iOS and Android (McGraw-Hill Education, 2010) About the Technical Editor

Related Documents:

appointment. If you cancel: 25.1. any time up to 24 hours before the appointment you will receive a full refund; and 25.2. within 24 hours of the appointment, you will not receive any refund. 26. Refunds will only be paid to the cardholder or person who made the original payment and will be made through the same means as payment was made. 27 .

the business world; new business practices such as offshoring challenge companies to manage at a distance; and new forms of accountability, such as corporate governance and corporate social responsibility, put added pressure on companies to match their words with deeds, wherever they are operating. One response has been the shift from functional to matrix structures, where companies organise .

Lesson Plan for Day One Teaching a Leisure Activity Lesson Title/Topic: Calligraphy Duration: an hour and a half. Supplies/Equipment Learning

Cambridge International AS and A Level Literature in English 9695 3 How to use this guide The guide describes what you need to know about your Cambridge International AS and A Level Literature in English examinations, and offers some thoughts about how you might revise the work you have done during the past year (AS Level) or two years (A Level). It will help you to plan your revision .

CREATIO CERTIFICATION CREATIO ANALYST Basic Advanced Basic Advanced CREATIO DEVELOPER Certification process consists of a practical assignment and an online exam (1 hour) The exam is conducted individually by an Academy trainer during an appointed certification session The certification process involves several stages: Registration and payment Obtaining and completing the practial assignment .

T: 44 (0) 203 824 1419 E: cips@harleyreed.com www.harleyreed.com 3.0 ADDITIONAL INFORMATION 1. Our standard Enhanced Gold programme is a mixture of classroom workshops and online materials. This is particularly useful for exam practice on the Objective Response units. Individuals are strongly advised to attend all classroom sessions. For .

Certificate in Procurement and Supply – Level 2 Duration: 6 months - Day, Evening and Long Distance classes This is an ideal qualification if you are just starting your career in procurement or if procurement and supply operations are part of your role. It will enable you to recognise and describe the key processes in procurement and build your professional knowledge and competence. Based on .

THE CODE OF CIVIL PROCEDURE, 1908 (ACT NO. V OF 1908). [21st March, 1908] the Courts of Civil Judicature. 1 An Act to consolidate and amend the laws relating to the Procedure of WHEREAS it is expedient to consolidate and amend the laws relating to the procedure of the Courts of Civil Judicature; It is hereby enacted as follows:- PRELIMINARY Short title, commencement and extent 1.(1) This Act .