Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
ECMAScript Cookbook
ECMAScript Cookbook

ECMAScript Cookbook: Over 70 recipes to help you learn the new ECMAScript (ES6/ES8) features and solve common JavaScript problems

Arrow left icon
Profile Icon Harrison
Arrow right icon
₱1256.99 ₱1796.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3 (3 Ratings)
eBook Mar 2018 348 pages 1st Edition
eBook
₱1256.99 ₱1796.99
Paperback
₱2245.99
Subscription
Free Trial
Arrow left icon
Profile Icon Harrison
Arrow right icon
₱1256.99 ₱1796.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3 (3 Ratings)
eBook Mar 2018 348 pages 1st Edition
eBook
₱1256.99 ₱1796.99
Paperback
₱2245.99
Subscription
Free Trial
eBook
₱1256.99 ₱1796.99
Paperback
₱2245.99
Subscription
Free Trial

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

ECMAScript Cookbook

Staying Compatible with Legacy Browsers

In this chapter, we will cover the following recipes:

  • Installing Node.js with NVM
  • Installing and configuring webpack
  • Adding fallback script tags to load client bundles
  • Shimming methods with Babel Polyfill
  • Supporting new language features with Babel
  • Using tools to analyze webpack bundles

Introduction

In the preceding chapter, we covered how to take advantage of the new ECMAScript modules to load code from multiple files and organize our code. This cutting-edge technique has only recently become available in browsers. In practice, production websites try to target as many users as possible. This often means targeting older browsers. In addition, JavaScript also runs in other environments (such as Node.js) that do not support ECMAScript modules.

The good news is that we don't have to change our source code in order to support these platforms. There are tools available that produce a single JavaScript file from multiple source files. This way we can use modules to organize our code, and run our programs on more platforms.

The recipes in this chapter focus on installation and configuration of webpack in order to provide a fallback option for platforms that...

Installing Node.js with NVM – Linux and macOS

Node provides installation binaries for Windows and macOS on its website:
https://nodejs.org/en/download/.

It's easy to install Node.js by downloading the appropriate installer for your OS and processor. However, it is useful to have a version manager so that you can work on projects that require different versions, and use the latest version. This is especially useful if your package manager doesn't provide a recent version of Node.js (for example, Ubuntu).

Subsequent recipes will assume that Node.js is installed. This recipe demonstrates how to install Node.js for Linux and macOS. The next recipe will cover the installation instructions for Windows.

Getting ready

...

Installing Node.js with NVM: Windows

Subsequent recipes will assume that Node.js is installed. This recipe demonstrates how to install Node.js for Windows.

Getting ready

This recipe is meant for the Windows environment. See the previous recipe for macOS and Linux instructions.

You must also have git installed. You can download git from the following link:

https://git-scm.com/download/win.

How to do it...

Installing and configuring webpack

As mentioned before, there are a few options for creating JavaScript bundles. Rollup and Babel are popular tools that can perform this task. The webpack is a good option because it is widely used and has a large plugin base.

This recipe demonstrates how to install and configure webpack to build a JavaScript bundle.

Getting ready

You'll need to have Node.js installed. If not, please see the appropriate recipe for installing Node.js with nvm.

How to do it...

  1. Open your command-line application, navigate to your workspace, and create...

Adding fallback script tags to load client bundles

In the previous recipe, we showed how to combine multiple modules with webpack. This recipe demonstrates how to load these into browsers that don't support ES modules.

Getting ready

This recipe assumes that you have webpack installed and configured. It is suggested that you complete the previous recipe, Installing and configuring webpack, before continuing with this recipe.

You will also need to have Python installed. If you haven't yet, visit the Installing Python, using SimpleHTTPServer to host a local static file server recipe in Chapter 1, Building with Modules.

...

Shimming methods with Babel Polyfill

In the previous two recipes, we saw how to create a client bundle and load it into a browser. This make it possible to use ES modules in source code without breaking compatibility with older browsers.

However, there are also new methods available in newer versions of the language that we'll be using in later chapters.

This recipe demonstrates how to use the babel-polyfill library to support those methods.

Getting ready

This recipe assumes that you have the code created in earlier recipes in this chapter, and that you have installed Python and know how to start the static HTTP server. Please visit the earlier recipes or copy the code.

...

Supporting new language features with Babel

In the previous recipe, we saw how to use the babel-polyfill library to support new ES methods. This add methods to the language at runtime, so that source code that depends on them runs correctly.

There are other language features that are relatively new to ECMAScript, such as the arrow function, let and const variable declarations, and spread operators. These features are not universally supported. Babel provides a mechanism to use them at the source level, and remain compatible with a build step.

This recipe demonstrates how to use Babel within webpack, in order to support these features in older browsers.

Getting ready

This recipe assumes that you have the code created in earlier...

Using tools to analyze webpack bundles

A major disadvantage of transpiling and using Polyfills is that the source code can diverge quite dramatically from the source code. This can often result in bloated bundle sizes. If you look at the file size of the bundle.js file after the Polyfill library was added (see the previous two recipes), then you'll see that it is over 200Kb. This is quite large when compared to 5Kb without the Polyfill.

With many bundles, it is difficult to find out what files are responsible for the large file size, and what the dependencies are between them.

In this recipe, we will see how to use analysis tools to get a better perspective on our webpack bundles.

Getting ready

It will be helpful to have...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Learn to write asynchronous code and improve the readability of your web applications
  • Explore advanced concepts such as closures, Proxy, generators, Promise, async functions, and Atomics
  • Use different design patterns to create structures to solve common organizational and processing issues

Description

ECMAScript Cookbook follows a modular approach with independent recipes covering different feature sets and specifications of ECMAScript to help you become an efficient programmer. This book starts off with organizing your JavaScript applications as well as delivering those applications to modem and legacy systems. You will get acquainted with features of ECMAScript 8 such as async, SharedArrayBuffers, and Atomic operations that enhance asynchronous and parallel operations. In addition to this, this book will introduce you to SharedArrayBuffers, which allow web workers to share data directly, and Atomic operations, which help coordinate behavior across the threads. You will also work with OOP and Collections, followed by new functions and methods on the built-in Object and Array types that make common operations more manageable and less error-prone. You will then see how to easily build more sophisticated and expressive program structures with classes and inheritance. In the end, we will cover Sets, Maps, and Symbols, which are the new types introduced in ECMAScript 6 to add new behaviors and allow you to create simple and powerful modules. By the end of the book, you will be able to produce more efficient, expressive, and simpler programs using the new features of ECMAScript. ?

Who is this book for?

If you’re a web developer with a basic understanding of JavaScript and wish to learn the latest features of ECMAScript for developing efficient web applications, this book is for you.

What you will learn

  • • Organize JavaScript programs across multiple files, using ES modules
  • • Create and work with promises using the Promise object and methods
  • • Compose async functions to propagate and handle errors
  • • Solve organizational and processing issues with structures using design patterns
  • • Use classes to encapsulate and share behavior
  • • Orchestrate parallel programs using WebWorkers, SharedMemory, and Atomics
  • • Use and extend Map, Set, and Symbol to work with user-defined classes and simulate data types
  • • Explore new array methods to avoid looping with arrays and other collections

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Mar 30, 2018
Length: 348 pages
Edition : 1st
Language : English
ISBN-13 : 9781788625630
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Mar 30, 2018
Length: 348 pages
Edition : 1st
Language : English
ISBN-13 : 9781788625630
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₱260 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₱260 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 6,992.97
ECMAScript Cookbook
₱2245.99
Vue.js 2 Design Patterns and Best Practices
₱2500.99
Learn ECMAScript
₱2245.99
Total 6,992.97 Stars icon
Banner background image

Table of Contents

13 Chapters
Building with Modules Chevron down icon Chevron up icon
Staying Compatible with Legacy Browsers Chevron down icon Chevron up icon
Working with Promises Chevron down icon Chevron up icon
Working with async/await and Functions Chevron down icon Chevron up icon
Web Workers, Shared Memory, and Atomics Chevron down icon Chevron up icon
Plain Objects Chevron down icon Chevron up icon
Creating Classes Chevron down icon Chevron up icon
Inheritance and Composition Chevron down icon Chevron up icon
Larger Structures with Design Patterns Chevron down icon Chevron up icon
Working with Arrays Chevron down icon Chevron up icon
Working with Maps and Symbols Chevron down icon Chevron up icon
Working with Sets Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3
(3 Ratings)
5 star 66.7%
4 star 0%
3 star 33.3%
2 star 0%
1 star 0%
Amazon Customer Sep 28, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Very informative writing! Great book!
Amazon Verified review Amazon
Angel Martínez May 21, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Casi diría excelente. Muy bien explicado y maquetado, con ejemplos prácticos y como dirían algunos "currado". Espero que las editoriales españolas aprendan como hacer un buen libro. Mucho me temo que no lo harán.
Amazon Verified review Amazon
YouCanHandleMyTruth May 16, 2018
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
It's ok. Gives you some concrete examples but I felt like there needed to be some my why's and now how.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.