Home Web Front-end JS Tutorial What's new in ES2017: Async functions, improved objects and more

What's new in ES2017: Async functions, improved objects and more

Feb 15, 2025 pm 12:33 PM

What’s new in ES2017: Async functions, improved objects and more

ES2017 (ECMAScript 2017) has introduced several important updates to JavaScript, which will focus on and briefly outline its update process.

Core points

  • Async functions: Allows you to write asynchronous code based on Promise like you write synchronous code. This feature is supported in all modern browsers (except IE and Opera Mini) and Node.js 7.6.
  • New methods for object processing: include Object.values(), Object.entries() and Object.getOwnPropertyDescriptors(). These methods are supported in most modern browsers and Node.js 7.0.
  • String fill methods (.padStart() and .padEnd()): Simplify string formatting. All modern browsers (except IE) and Node.js 8.0 are supported.
  • Save trailing commas:Save trailing commas in object definitions, array declarations, function parameter lists, etc. All browsers and Node.js are supported. Trailing commas in function parameters are supported only in Chrome 58 and Firefox 52 at the time of writing.

Update process

JavaScript (ECMAScript) standards are constantly evolving and are implemented by many manufacturers on multiple platforms. ES6 (ECMAScript 2015) took six years to finally be completed and is huge in scale. To simplify the process and quickly add new features, a new annual release process was developed.

Technical Committee 39 (TC39) is composed of participants such as browser manufacturers who follow a strict process to advance JavaScript's proposal:

Stage 0: Strawman – A preliminary idea of ​​new or improved ECMAScript capabilities.

Stage 1: Proposal – A formal proposal document advocated by at least one TC39 member, including API examples, language semantics, algorithms, potential obstacles, polyfills, and demonstrations.

Stage 2: Draft – The initial version of the functional specification. Two experimental implementations are required, one of which can be implemented in a translator such as Babel.

Stage 3: Candidate – Review the proposal specifications and collect feedback from the vendor.

Stage 4: Finished – The proposal is ready to be included in ECMAScript. Only functions that reach this stage are considered standard. However, it may take longer to release in runtimes like browsers and Node.js.

ES2016 is small in scale and is designed to validate standardized processes. Two new features have been added:

  1. Array's .includes() method returns true or false when the array contains a value.
  2. a ** b power operator, the same as Math.pow(a, b).

New features of ES2017

ES2017 (or formerly known as ES8) is considered to be the first appropriate revision of the ECMAScript specification. It provides the following features...

Async function

Unlike most languages, JavaScript is asynchronous by default. Commands that may take any time will not stop executing. This includes operations such as requesting URLs, reading files, or updating databases. A callback function must be passed that is executed when the result of the operation is known.

This can lead to callback hell when a series of nested asynchronous functions must be executed sequentially. For example:

function doSomething() {
  doSomething1((response1) => {
    doSomething2(response1, (response2) => {
      doSomething3(response2, (response3) => {
        // etc...
      };
    });
  });
}
Copy after login

ES2015 (ES6) introduces Promise, which provides a clearer way to express the same functionality. Once your functions are Promisified, they can be executed using the following methods:

function doSomething() {
  doSomething1()
  .then(doSomething2)
  .then(doSomething3)
}
Copy after login

ES2017 Asynchronous function extends Promise to make asynchronous calls clearer:

async function doSomething() {
  const
    response1 = await doSomething1(),
    response2 = await doSomething2(response1),
    response3 = await doSomething3(response2);
}
Copy after login

await Effectively make each call look synchronous without consuming a single processing thread in JavaScript.

Async functions are supported in all modern browsers (except IE and Opera Mini) and in Node.js 7.6. They will change the way you write JavaScript and can write a special article about callbacks, promises, and asynchronous functions.

The descriptions of

Object.values(), Object.entries(), Object.getOwnPropertyDescriptors(), .padStart(), .padEnd() and

and the trailing commas are similar to the original text and will not be repeated here.

SharedArrayBuffer and Atomics

SharedArrayBuffer objects are used to represent fixed-length raw binary data buffers that can be shared among Web Workers. Atomics objects provide a predictable way to read and write memory locations defined by SharedArrayBuffer.

While both Chrome and Firefox implement both objects, it was disabled in January 2018 due to a Spectre vulnerability.

The complete ECMAScript 2017 language specification is available on the ECMA International website.

ES2017 FAQ (FAQ)

(The FAQ part is similar to the original text, and will not be repeated here. You can selectively retain or rewritten as needed.)

The above is the detailed content of What's new in ES2017: Async functions, improved objects and more. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

Hot Article

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Replace String Characters in JavaScript Replace String Characters in JavaScript Mar 11, 2025 am 12:07 AM

Replace String Characters in JavaScript

jQuery Check if Date is Valid jQuery Check if Date is Valid Mar 01, 2025 am 08:51 AM

jQuery Check if Date is Valid

jQuery get element padding/margin jQuery get element padding/margin Mar 01, 2025 am 08:53 AM

jQuery get element padding/margin

Top 5 Date Manipulation JS Plugins Top 5 Date Manipulation JS Plugins Feb 28, 2025 am 12:34 AM

Top 5 Date Manipulation JS Plugins

10 jQuery Accordions Tabs 10 jQuery Accordions Tabs Mar 01, 2025 am 01:34 AM

10 jQuery Accordions Tabs

10 Worth Checking Out jQuery Plugins 10 Worth Checking Out jQuery Plugins Mar 01, 2025 am 01:29 AM

10 Worth Checking Out jQuery Plugins

jquery add scrollbar to div jquery add scrollbar to div Mar 01, 2025 am 01:30 AM

jquery add scrollbar to div

HTTP Debugging with Node and http-console HTTP Debugging with Node and http-console Mar 01, 2025 am 01:37 AM

HTTP Debugging with Node and http-console

See all articles