📜 ⬆️ ⬇️

The book "ECMAScript 6 for Developers"

image Get to know the radical changes in the JavaScript language that have occurred thanks to the new ECMAScript 6 standard. Nicholas Zakas - best-selling author and expert developer - has created the most comprehensive guide to new types of objects, syntax, and interesting features. Each chapter contains examples of programs that will work in any JavaScript environment and introduce you to new language features. After reading this book, you will learn about how useful iterators and generators are, how reference functions differ from ordinary ones, what additional options allow working with data, about type inheritance, about asynchronous programming, about how modules change the way code is organized, and much a friend.

Moreover, Nicholas Zakas looks into the changes that appeared in ECMAScript 7. It doesn't matter if you are a web developer or working with node.js, in this book you will find the most necessary information that allows you to effectively use all the features of ECMAScript 6.

Who is the book for?


This book was conceived as a guide for those who are already familiar with JavaScript and ECMAScript 5. Although deep knowledge of the language is not a prerequisite for working with this book, it will help you understand the differences between ECMAScript 5 and 6. In particular, this book is addressed to developers in JavaScript with browser programming experience or Node.js who want to learn about the latest innovations in the language.

This book is definitely not for beginners who have never written in JavaScript. To read this book you need to know well at least the basics of the language.
')

Content overview


All chapters and applications in this book cover different aspects of ECMAScript 6. Many chapters begin with a discussion of the problems that ECMAScript 6 addresses to address, so that you get a broader view of these changes. All chapters include code samples that demonstrate new ideas and syntactic constructs.

• Chapter 1, “Block Bindings,” discusses the let and const statements, replacing the var statement at the block level.

• Chapter 2, "Strings and Regular Expressions", covers additional string functions, as well as introduces patterned strings.

• Chapter 3, “Functions,” discusses various changes that affect functions, including arrow functions, parameters with default values, residual parameters, and some other features.

• Chapter 4, “Advanced Object Features,” explains the changes in approaches to creating, modifying, and using objects. Among the topics considered are changes in the syntax of object literals and new methods of reflection.

• Chapter 5, “Restructuring to simplify data access,” introduces the syntax for destructuring objects and arrays, allowing for the partitioning of objects and arrays using a compact syntax.

• Chapter 6, “Symbols and Symbolic Properties,” introduces the idea of ​​symbols — a new way to define properties. Symbols are a new simple data type that can be used to hide (although not completely) the properties and methods of objects.

• Chapter 7, “Sets and Associative Arrays,” describes new types of collections: Set, WeakSet, Map, and WeakMap. These types add to regular arrays a guarantee of uniqueness of values ​​and memory management tools designed specifically for JavaScript.

• Chapter 8, Iterators and Generators, discusses adding iterators and generators to the language. These tools open up new powerful ways to work with data collections that are not available in previous versions of JavaScript.

• Chapter 9, Introduction to JavaScript Classes, introduces the first formalized concept of classes in JavaScript. An object-oriented model in JavaScript often causes confusion for programmers who have migrated from other languages. New additional syntax for working with classes makes JavaScript more accessible to others and expressive for enthusiasts.

• Chapter 10, Advanced Arrays, describes changes to ordinary arrays and new ways to use them in JavaScript.

• Chapter 11, "The Promise Object and Asynchronous Programming" introduces the objects of asynchronous computing (Promise) - a new language element. Objects of asynchronous computing were the result of massive efforts and quickly gained popularity due to extensive support in libraries. The ECMAScript 6 specification formalized these objects and made them available by default.

• Chapter 12, Proxy Objects and Reflection API, introduces the JavaScript reflection application interface and new proxy objects that allow you to intercept any operations on an object. Proxy objects give developers unprecedented control over objects and, as a result, unlimited possibilities for defining new interaction patterns.

• Chapter 13, “Encapsulating Code into Modules,” describes the official format of modules for JavaScript. Its goal is to replace the numerous non-standard format definition modules that have emerged over the years of the language.

• Appendix A “Minor Changes in ECMAScript 6” covers other changes in ECMAScript 6, rarely used or not associated with the larger changes described in previous chapters.

• Appendix B “Introduction to ECMAScript 7 (2016)” describes three standard additions included in the ECMAScript 7 edition, which does not have such a significant effect on JavaScript as ECMAScript 6.

The work on ECMAScript 6 took several years, and as a result, the TC-39 technical committee concluded that this development process was completely unacceptable. Therefore, it was decided to switch to the annual release cycle of changes in order to guarantee a faster introduction of new features into the language.

More frequent releases imply fewer innovations in each subsequent edition of ECMAScript than in ECMAScript 6. To mark the transition to a new cycle, it was decided to number the new versions of the specification not by the revision number, but by the number of the year of publication. As a result, ECMAScript 6 is now also known as ECMAScript 2015, and ECMAScript 7 is formally called ECMAScript 2016. The TC-39 committee proposes to use the naming system with the year number in all future ECMAScript editions.

The work on the ECMAScript 2016 edition was completed in March 2016 and includes only three language additions: a new mathematical operator, a new array method, and a new syntax error. All three innovations are discussed further in this application.

Exponentiation operator


The only change in the JavaScript syntax provided for in ECMAScript 2016 is the exponentiation operator that performs the same mathematical operation. JavaScript already has a Math.pow () method that performs exponentiation, but JavaScript has remained one of the few languages ​​that requires the use of a method instead of a formal operator. In addition, some developers claim that the statement is easier to read in code.

The exponentiation operator has the form of two asterisks (**): the left operand is used as the base, and the right operand is used as the degree. For example:

let result = 5 ** 2; console.log(result); // 25 console.log(result === Math.pow(5, 2)); // true 

This example calculates expression 5 to the second degree, the result of which is 25. If desired, the same calculations can still be performed using the Math.pow () method.

Order of operations


The exponentiation operator has the highest priority of all binary operators in JavaScript (unary operators have a higher priority than **). This means that it is executed first in any complex expression, for example:

 let result = 2 * 5 ** 2; console.log(result); // 50 

Here, first the result will be found 5 in the second degree, then the resulting value is multiplied by 2. The end result will be equal to 50.

Operand Constraints


The exponentiation operator imposes some unusual restrictions that are absent in other operators. The left operand cannot be an expression with a unary operator, except ++ and -. For example, the following example will cause a syntax error:

 //   let result = -5 ** 2; 

The expression -5 in this example is regarded as a syntax error, because there is ambiguity in determining the order of operations. Should the unary operator be applied to the number 5 or to the result of the expression 5 ** 2? Prohibiting the use of unary expressions to the left of the exponentiation operator removes this ambiguity. To clearly state your intentions, you must enclose the parentheses -5 or 5 ** 2, as shown below:

 //  let result1 = -(5 ** 2); //   -25 //   let result2 = (-5) ** 2; //   25 

If you enclose an expression in parentheses, the unary operator will be applied to the whole expression. If we put in -5 round brackets, the interpreter will understand that it is necessary to raise the number —5 to the second degree.

Expressions with ++ and - operators to the left of the exponentiation operator are not required to be enclosed in brackets, because the behavior of both operators is clearly defined as directed to their operands. The prefix operator ++ or - changes its operand before performing any other operation, and the postfix versions change nothing until the entire expression is evaluated. In both cases, these operators do not cause errors when used to the left of the exponentiation operator, for example:

 let num1 = 2, num2 = 2; console.log(++num1 ** 2); // 9 console.log(num1); // 3 console.log(num2-- ** 2); // 4 console.log(num2); // 1 

In this example, the value of num1 is increased before executing the exponentiation operator, so num1 is set to 3, and the result is 9. The variable num2 retains the value 2 before executing the exponentiation operator and then decreases to 1.

about the author


Nicholas Zakas (Nicholas Zakas) has been developing web applications, mostly client-side, since 2000 and is widely known for his books and lectures on advanced techniques for developing user interfaces. For five years, he honed his experience working at Yahoo !, where he served as the lead engineer responsible for the Yahoo home page! .. Author of several books, including Principles of Object-Oriented JavaScript (No Starch Press, 2014) and Professional JavaScript for Web Developers (Wrox, 2012).

About science editor


Yuri Zaitsev (Juriy Zaytsev, known under the pseudonym kangax) is a web developer living in New York. Explores and writes about the unusual nature of JavaScript since 2007. Contributes to the development of several open source projects, including Prototype.js, and other popular projects, such as his own Fabric.js. Co-founder of the company printio.ru, dealing with printing to order. Currently working on Facebook.

»More information about the book can be found on the publisher's website.
» Table of Contents
» Excerpt

For Habrozhiteley 25% coupon discount - ECMAScript

Source: https://habr.com/ru/post/327730/


All Articles