Home >Web Front-end >JS Tutorial >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
Object.values()
, Object.entries()
and Object.getOwnPropertyDescriptors()
. These methods are supported in most modern browsers and Node.js 7.0. 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:
.includes()
method returns true or false when the array contains a value. 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:
<code class="language-javascript">function doSomething() { doSomething1((response1) => { doSomething2(response1, (response2) => { doSomething3(response2, (response3) => { // etc... }; }); }); }</code>
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:
<code class="language-javascript">function doSomething() { doSomething1() .then(doSomething2) .then(doSomething3) }</code>
ES2017 Asynchronous function extends Promise to make asynchronous calls clearer:
<code class="language-javascript">async function doSomething() { const response1 = await doSomething1(), response2 = await doSomething2(response1), response3 = await doSomething3(response2); }</code>
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 ofObject.values()
, Object.entries()
, Object.getOwnPropertyDescriptors()
, .padStart()
, .padEnd()
and
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!