Book description
Problem solving with JavaScript is a lot trickier now that its use has expanded considerably in size, 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 recipe includes reusable code and practical advice for tackling JavaScript objects, Node, Ajax, JSON, data persistence, graphical and media applications, complex frameworks, modular JavaScript, APIs, and many related technologies.
Publisher resources
Table of contents
- The World of JavaScript
-
I. Classic JavaScript
-
1. The JavaScript Not-So-Simple Building Blocks
- Differentiating Between a JavaScript Object, Primitive, and Literal
- Extracting a List from a String
- Checking for an Existing, Nonempty String
- Inserting Special Characters
- Replacing Patterns with New Strings
- Finding and Highlighting All Instances of a Pattern
- Swapping Words in a String Using Capturing Parentheses
- Replacing HTML Tags with Named Entities
- Converting an ISO 8601 Formatted Date to a Date Object Acceptable Format
- Using Function Closures with Timers
- Tracking Elapsed Time
- Converting a Decimal to a Hexadecimal Value
- Summing All Numbers in a Table Column
- Converting Between Degrees and Radians
- Find the Radius and Center of a Circle to Fit Within a Page Element
- Calculating the Length of a Circular Arc
- Using ES6 String Extras Without Leaving Users in the Dirt
-
2. JavaScript Arrays
- Searching Through an Array
- Flattening a Two-Dimensional Array with concat() and apply()
- Removing or Replacing Array Elements
- Extracting a Portion of an Array
- Applying a Function Against Each Array Element
- Traversing the Results from querySelectorAll() with forEach() and call()
- Applying a Function to Every Element in an Array and Returning a New Array
- Creating a Filtered Array
- Validating Array Contents
- Using an Associative Array to Store Form Element Names and Values
- Using a Destructuring Assignment to Simplify Code
-
3. Functions: The JavaScript Building Blocks
- Placing Your Function and Hoisting
- Passing a Function As an Argument to Another Function
- Implementing a Recursive Algorithm
- Preventing Code Blocking with a Timer and a Callback
- Creating a Function That Remembers Its State
- Converting Function Arguments into an Array
- Reducing Redundancy by Using a Partial Application
- Improving Application Performance with Memoization (Caching Calculations)
- Using an Anonymous Function to Wrap Global Variables
- Providing a Default Parameter
-
4. The Malleable JavaScript Object
- Keeping Object Members Private
- Using Prototype to Create Objects
- Inheriting an Object’s Functionality
- Extending an Object by Defining a New Property
- Preventing Object Extensibility
- Preventing Any Changes to an Object
- Namespacing Your JavaScript Objects
- Rediscovering this with Prototype.bind
- Chaining Your Object’s Methods
-
5. JavaScript and Directly Accessing the User Interface
- Accessing a Given Element and Finding Its Parent and Child Elements
- Accessing All Images in the Web Page
- Discovering All Images in Articles Using the Selectors API
- Setting an Element’s Style Attribute
- Applying a Striped Theme to an Unordered List
- Finding All Elements That Share an Attribute
- Inserting a New Paragraph
- Adding Text to a New Paragraph
- Deleting Rows from an HTML Table
- Adding a Page Overlay
- Creating Collapsible Form Sections
- Hiding Page Sections
- Creating Hover-Based Pop-Up Info Windows
- Displaying a Flash of Color to Signal an Action
- 6. Preliminary Testing and Accessibility
-
7. Creating and Using JavaScript Libraries
- Finding the Perfect Library
- Testing for Features with Modernizr.load
- Going Beyond the Math Object’s Capability
- Finding the Number of Days Between Two Dates
- Using an External Library: Building on the jQuery Framework
- Using a jQuery Plugin
- Handling Keyboard Shortcuts with Mousetrap
- Utilizing the Utility Library Underscore
- Packaging Your Code
- Adding Support for Private Data Members
- Minify Your Library
- Hosting Your Library
- Serving Code from a CDN
- Convert Your Library to a jQuery Plug-in
- Safely Combining Several Libraries in Your Applications
-
8. Simplified Client-Server Communication and Data
- Handling an XML Document Returned via an Ajax Call
- Extracting Pertinent Information from an XML Tree
- Parsing and Automatically Modifying JSON
- Converting an Object to a Filtered/Transformed String with JSON
- Making an Ajax Request to Another Domain (Using JSONP)
- Processing JSON from an Ajax Request
- Populating a Selection List from the Server
- Using a Timer to Automatically Update the Page with Fresh Data
- 9. Creating Media Rich, Interactive Web Effects
-
1. The JavaScript Not-So-Simple Building Blocks
-
II. JavaScript, All Blown Up
-
10. The New ECMAScript Standard Objects
- Using let in Your Browser Application
- Creating a Collection of Non-Duplicated Values
- Creating Unique Key/Value Pairs with Uniquely Different Keys
- Creating Absolutely Unique Object Property Keys
- Iterating Through Tasks Made Easy
- Creating Functions that Gracefully Yield
- Implementing Just-in-Time Object Behavioral Modifications with Proxies
- Creating a True Class and Extending It (with a Little Help from Traceur)
- Using Promises for Efficient Asynchronous Processing
-
11. Node: JavaScript on the Server
- Responding to a Simple Browser Request
- Serving Up Formatted Data
- Reading and Writing File Data
- Using let and Other ES 6 Additions in Node
- Interactively Trying Out Node Code Snippets with REPL
- Getting Input from the Terminal
- Working with Node Timers and Understanding the Node Event Loop
- Managing Callback Hell
- Accessing Command-Line Functionality Within a Node Application
- Running Node and Apache on the Same Port
- Keeping a Node Instance Up and Running
- Monitoring Application Changes and Restarting
- Screen Scraping with Request
- Creating a Command-Line Utility with Help From Commander
-
12. Modularizing and Managing JavaScript
- Loading Scripts with a Script Loader
- Loading Scripts Asynchronously the HTML5 Way
- Converting Your JavaScript to AMD and RequireJS
- Using RequireJS with jQuery or Another Library
- Loading and Using Dojo Modules
- Installing and Maintaining Node Modules with npm
- Searching for a Specific Node Module via npm
- Converting Your Library into a Node Module
- Taking Your Code Across All Module Environments
- Creating an Installable Node Module
- Packaging and Managing Your Client-Side Dependencies with Bower
- Compiling Node.js Modules for Use in the Browser with Browserify
- Unit Testing Your Node Modules
- Running Tasks with Grunt
-
13. Fun with APIs
- Accessing JSON-Formatted Data via a RESTful API
- Creating a RESTFul API with Restify
- Enabling a Mobile-Like Notification in the Desktop Browser
- Loading a File Locally in the Browser
- Creating a Mini E-Pub Reader Using Web Workers and the File API
- Exploring Google Maps and Other APIS
- Accessing Twitter’s API from a Node Application
- 14. JavaScript Frameworks
-
15. Advanced Client-Server Communications and Streams
- Allowing Cross-Domain Requests
- Implementing a PUT Request in Ajax
- Sending Binary Data Through Ajax and Loading into an Image
- Sharing HTTP Cookies Across Domains
- Establishing Two-Way Communication Between Client and Server
- Unloading and Zipping Files Using Transform Streams
- Testing the Performance and Capability of Your WebSockets Application
- 16. Data Visualizations and Client/Server Graphics
-
17. Data and Persistence
- Validating Form Data
- Persisting Information Using HTML5
- Using sessionStorage for Client-Side Storage
- Creating a localStorage Client-Side Data Storage Item
- Using Squel.js to Query a MySQL Database
- Persisting Larger Chunks of Data on the Client Using IndexedDB
- Accessing Data in the Cloud Using Dropbox Datastores
-
18. JavaScript Hits the (Mobile) Road
- Creating an Installable, Hosted Web App
- Packaging Web Apps for the Amazon Appstore
- Building a Basic Android App Using Cordova (PhoneGap)
- Porting Where Am I? to Android
- Creating a Geolocation Firefox OS App
- Porting the Geolocation App to a Google Chrome App
- Publishing Your Geolocation App in the Kindle Fire OS Environment
- Debugging Your Android or Amazon Fire OS App
- Getting Information About the Device
- A. Up and Running in jsBin and jsFiddle
-
10. The New ECMAScript Standard Objects
- Index
- Colophon
- Copyright
Product information
- Title: JavaScript Cookbook, 2nd Edition
- Author(s):
- Release date: February 2015
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781491901885
You might also like
book
JavaScript Cookbook, 3rd Edition
Why reinvent the wheel every time you run into a problem with JavaScript? This cookbook is …
book
Learning JavaScript, 3rd Edition
This is an exciting time to learn JavaScript. Now that the latest JavaScript specification—ECMAScript 6.0 (ES6)—has …
book
Eloquent JavaScript, 3rd Edition
JavaScript lies at the heart of almost every modern web application, from social apps like Twitter …
book
JavaScript: The Definitive Guide, 6th Edition
Since 1996, JavaScript: The Definitive Guide has been the bible for JavaScript programmers—a programmer's guide and …