scope, and complexity. This cookbook has your back, with recipes for common tasks across the
JavaScript world, whether you’re working in the browser, the server, or a mobile environment. Each
JSON, data persistence, graphical and media applications, complex frameworks, modular
Aimed at people who have some experience with JavaScript, the first part covers traditional uses of
JavaScript, along with new ideas and improved functionality. The second part dives into the server,
mobile development, and a plethora of leading-edge tools. You’ll save time—and learn more about
1. The JavaScript Not-So-Simple Building Blocks
1.1.Differentiating Between a JavaScript Object, Primitive, and Literal
1.2. Extracting a List from a String
1.3. Checking for an Existing, Nonempty String
1.4. Inserting Special Characters
1.5. Replacing Patterns with New Strings
1.6. Finding and Highlighting All Instances of a Pattern
1.7. Swapping Words in a String Using Capturing Parentheses
1.8. Replacing HTML Tags with Named Entities
1.9. Converting an ISO 86
01 Formatted Date to a Date Object Acceptable Format
1.10. Using Function Closures with Timers
1.11. Tracking Elapsed Time
1.12. Converting a Decimal to a Hexadecimal Value
1.13. Summing All Numbers in a Table Column
1.14. Converting Between Degrees and Radians
1.15. Find the Radius and Center of a Circle to Fit Within a Page Element
1.16. Calculating the Length of a Circular Arc
1.17. Using ES6 String Extras Without Leaving Users in the Dirt
2. JavaScript Arrays
2.1. Searching Through an Array
2.2. Flattening a Two-Dimensional Array with concat() and apply()
2.3. Removing or Replacing Array Elements
2.4. Extracting a Portion of an Array
2.5. Applying a Function Against Each Array Element
2.6. Traversing the Results from querySelectorAll() with forEach() and call()
2.7. Applying a Function to Every Element in an Array and Returning a New Array
2.8. Creating a Filtered Array
2.9. Validating Array Contents
2.10. Using an Associative Array to Store Form Element Names and Values
2.11. Using a Destructuring Assignment to Simplify Code
3. Functions: The JavaScript Building Blocks
3.1. Placing Your Function and Hoisting
3.2. Passing a Function As an Argument to Another Function
3.3. Implementing a Recursive Algorithm
3.4. Preventing Code Blocking with a Timer and a Callback
3.5. Creating a Function That Remembers Its State
3.6. Converting Function Arguments into an Array
3.7. Reducing Redundancy by Using a Partial Application
3.8. Improving Application Performance with Memoization (Caching Calculations)
3.9. Using an Anonymous Function to Wrap Global Variables
3.10. Providing a Default Parameter
4. The Malleable JavaScript Object
4.1. Keeping Object Members Private
4.2. Using Prototype to Create Objects
4.3. Inheriting an Object’s Functionality
4.4. Extending an Object by Defining a New Property
4.5. Preventing Object Extensibility
4.6. Preventing Any Changes to an Object
4.7. Namespacing Your JavaScript Objects
4.8. Rediscovering this with Prototype.bind
4.9. Chaining Your Object’s Methods
5. JavaScript and Directly Accessing the User Interface
5.1. Accessing a Given Element and Finding Its Parent and Child Elements
5.2. Accessing All Images in the Web Page
5.3. Discovering All Images in Articles Using the Selectors API
5.4. Setting an Element’s Style Attribute
5.5. Applying a Striped Theme to an Unordered List
5.6. Finding All Elements That Share an Attribute
5.7. Inserting a New Paragraph
5.8. Adding Text to a New Paragraph
5.9. Deleting Rows from an HTML Table
5.10. Adding a Page Overlay
5.11. Creating Collapsible Form Sections
5.12. Hiding Page Sections
5.13. Creating Hover-Based Pop-Up Info Windows
5.14. Displaying a Flash of Color to Signal an Action
6. Preliminary Testing and Accessibility
6.1. Cleaning Up Your Code with JSHint
6.2. Unit Testing Your Code with QUnit
6.3. Testing Your Application in Various Environments
6.4. Performance Testing Different Coding Techniques
6.5. Highlighting Errors Accessibly
6.6. Creating an Accessible Automatically Updated Region
7. Creating and Using JavaScript Libraries
7.1. Finding the Perfect Library
7.2. Testing for Features with Modernizr.load
7.3. Going Beyond the Math Object’s Capability
7.4. Finding the Number of Days Between Two Dates
7.5. Using an External Library: Building on the jQuery Framework
7.6. Using a jQuery Plugin
7.7. Handling Keyboard Shortcuts with Mousetrap
7.8. Utilizing the Utility Library Underscore
7.9. Packaging Your Code
7.10. Adding Support for Private Data Members
7.11. Minify Your Library
7.12. Hosting Your Library
7.13. Serving Code from a CDN
7.14. Convert Your Library to a jQuery Plug-in
7.15. Safely Combining Several Libraries in Your Applications
8. Simplified Client-Server Communication and Data
8.1. Handling an XML Document Returned via an Ajax Call
8.2. Extracting Pertinent Information from an XML Tree
8.3. Parsing and Automatically Modifying JSON
8.4. Converting an Object to a Filtered/Transformed String with JSON
8.5. Making an Ajax Request to Another Domain (Using JSONP)
8.6. Processing JSON from an Ajax Request
8.7. Populating a Selection List from the Server
8.8. Using a Timer to Automatically Update the Page with Fresh Data
9. Creating Media Rich, Interactive Web Effects
9.1. Creating a Dynamic Line Chart in Canvas
9.2. Adding JavaScript to SVG
9.3. Accessing SVG from Web Page Script
9.4. Integrating SVG and the Canvas Element in HTML
9.5. Running a Routine When an Audio File Begins Playing
9.6. Controlling Video from JavaScript with the video Element
9.7. Adding Filter Effects to Video via Canvas
Part II. JavaScript, All Blown Up
10. The New ECMAScript Standard Objects
10.1. Using let in Your Browser Application
10.2. Creating a Collection of Non-Duplicated Values
10.3. Creating Unique Key/Value Pairs with Uniquely Different Keys
10.4. Creating Absolutely Unique Object Property Keys
10.5. Iterating Through Tasks Made Easy
10.6. Creating Functions that Gracefully Yield
10.7. Implementing Just-in-Time Object Behavioral Modifications with Proxies
10.8. Creating a True Class and Extending It (with a Little Help from Traceur)
10.9. Using Promises for Efficient Asynchronous Processing
11. Node: JavaScript on the Server
11.1. Responding to a Simple Browser Request
11.2. Serving Up Formatted Data
11.3. Reading and Writing File Data
11.4. Using let and Other ES 6 Additions in Node
11.5. Interactively Trying Out Node Code Snippets with REPL
11.6. Getting Input from the Terminal
11.7. Working with Node Timers and Understanding the Node Event Loop
11.8. Managing Callback Hell
11.9. Accessing Command-Line Functionality Within a Node Application
11.10. Running Node and Apache on the Same Port
11.11. Keeping a Node Instance Up and Running
11.12. Monitoring Application Changes and Restarting
11.13. Screen Scraping with Request
11.14. Creating a Command-Line Utility with Help From Commander
12. Modularizing and Managing JavaScript
12.1. Loading Scripts with a Script Loader
12.2. Loading Scripts Asynchronously the HTML5 Way
12.3. Converting Your JavaScript to AMD and RequireJS
12.4. Using RequireJS with jQuery or Another Library
12.5. Loading and Using Dojo Modules
12.6. Installing and Maintaining Node Modules with npm
12.7. Searching for a Specific Node Module via npm
12.8. Converting Your Library into a Node Module
12.9. Taking Your Code Across All Module Environments
12.10. Creating an Installable Node Module
12.11. Packaging and Managing Your Client-Side Dependencies with Bower
12.12. Compiling Node.js Modules for Use in the Browser with Browserify
12.13. Unit Testing Your Node Modules
2.14. Running Tasks with Grunt
13. Fun with APIs
13.1. Accessing JSON-Formatted Data via a RESTful API
13.2. Creating a RESTFul API with Restify
13.3. Enabling a Mobile-Like Notification in the Desktop Browser
13.4. Loading a File Locally in the Browser
13.5. Creating a Mini E-Pub Reader Using Web Workers and the File API
13.6. Exploring Google Maps and Other APIS
13.7. Accessing Twitter’s API from a Node Application
14. JavaScript Frameworks
14.1. Using the Express-Generator to Generate an Express Site
14.2. Converting a Generated Express Site into a Basic MVC App
14.3. Choosing a SPA Framework: Deconstructing the TodoMVC
14.4. Working with the OAuth Framework
14.5. Extending the Possible with Web Components
15. Advanced Client-Server Communications and Streams
15.1. Allowing Cross-Domain Requests
15.2. Implementing a PUT Request in Ajax
15.3. Sending Binary Data Through Ajax and Loading into an Image
15.4. Sharing HTTP Cookies Across Domains
15.5. Establishing Two-Way Communication Between Client and Server
15.6. Unloading and Zipping Files Using Transform Streams
15.7. Testing the Performance and Capability of Your WebSockets Application
16. Data Visualizations and Client/Server Graphics
16.1. Creating an SVG Bar Chart with D3
16.2. Mapping Data Point Variations with a Radar Chart
16.3. Feeding a Scrolling Timeline via WebSocket
16.4. Generating Screenshots of Generated Web Page Content (PhantomJS)
16.5. Converting Graphics to Text (Ocrad.js)
16.6. Cropping (or Otherwise Modifying) Uploaded Images
17. Data and Persistence
17.1. Validating Form Data
17.2. Persisting Information Using HTML5
17.3. Using sessionStorage for Client-Side Storage
17.4. Creating a localStorage Client-Side Data Storage Item
17.5. Using Squel.js to Query a MySQL Database
17.6. Persisting Larger Chunks of Data on the Client Using IndexedDB
17.7. Accessing Data in the Cloud Using Dropbox Datastores
18. JavaScript Hits the (Mobile) Road
18.1. Creating an Installable, Hosted Web App
18.2. Packaging Web Apps for the Amazon Appstore
18.3. Building a Basic Android App Using Cordova (PhoneGap)
18.4. Porting Where Am I? to Android
18.5. Creating a Geolocation Firefox OS App
18.6. Porting the Geolocation App to a Google Chrome App
18.7. Publishing Your Geolocation App in the Kindle Fire OS Environment
18.8. Debugging Your Android or Amazon Fire OS App
18.9. Getting Information About the Device
A. Up and Running in jsBin and jsFiddle
Index
--------------------------------------------------------------------------------------------------------------
Type of File : PDF Book
Pages : 633
Size : 12.43 MB
--------------------------------------------------------------------------------------------------------------
0 Comments