ECMAScript 2017 (ES8) feature overview compiled from ES8 was Released and here are its Main New Features, summarized in the author's Modern JavaScript Development: Grammar Basics and Practical Skills series of articles; you are also welcome to pay attention to the front-end weekly checklist series to get first-hand Information.
ECMAScript 2017 or ES8 was officially released by TC39 at the end of June 2017. You can browse the complete version here; the representative features of ES8 include string padding, Object value traversal, object attribute descriptor acquisition, function parameter list and trailing commas in calls, asynchronous functions, shared memory and atomic operations, etc.
String filling
ES8 has added built-in string filling functions, namely padStart and padEnd. This function can ensure that the string reaches a fixed size by filling the head or tail of the string. Length; developers can specify the padded string or use default spaces. The function is declared as follows:
str.padStart(targetLength [, padString]) str.padEnd(targetLength [, padString])
As shown above, the first parameter of the function is the target length, which is the final generated The string length; the second parameter is the specified padding string:
'es8'.padStart(2); // 'es8' 'es8'.padStart(5); // ' es8' 'es8'.padStart(6, 'woof'); // 'wooes8' 'es8'.padStart(14, 'wow'); // 'wowwowwowwoes8' 'es8'.padStart(7, '0'); // '0000es8' 'es8'.padEnd(2); // 'es8' 'es8'.padEnd(5); // 'es8 ' 'es8'.padEnd(6, 'woof'); // 'es8woo' 'es8'.padEnd(14, 'wow'); // 'es8wowwowwowwo' 'es8'.padEnd(7, '6'); // 'es86666'
Object value traversal
Object.values function will return the enumerable The attribute value array of the example, the order of the values in the array is consistent with the for-in loop, the function declaration is:
Object.values(obj)
The first parameter obj is the target object that needs to be traversed, it can is an object or array (an array can be regarded as an object whose keys are subscripts):
const obj = { x: 'xxx', y: 1 }; Object.values(obj); // ['xxx', 1] const obj = ['e', 's', '8']; // same as { 0: 'e', 1: 's', 2: '8' }; Object.values(obj); // ['e', 's', '8'] // when we use numeric keys, the values returned in a numerical // order according to the keys const obj = { 10: 'xxx', 1: 'yyy', 3: 'zzz' }; Object.values(obj); // ['yyy', 'zzz', 'xxx'] Object.values('es8'); // ['e', 's', '8']
The Object.entries method will Enumeration properties and values are returned in the form of a two-dimensional array. The order in the array is consistent with Object.values. The declaration and use of this function are:
const obj = { x: 'xxx', y: 1 }; Object.entries(obj); // [['x', 'xxx'], ['y', 1]] const obj = ['e', 's', '8']; Object.entries(obj); // [['0', 'e'], ['1', 's'], ['2', '8']] const obj = { 10: 'xxx', 1: 'yyy', 3: 'zzz' }; Object.entries(obj); // [['1', 'yyy'], ['3', 'zzz'], ['10': 'xxx']] Object.entries('es8'); // [['0', 'e'], ['1', 's'], ['2', '8']]
Get the property descriptors of the object
The getOwnPropertyDescriptors function will return the descriptor of a specified property of the specified object; the property must be defined by the object itself rather than inherited from the prototype chain. The declaration of the function is:
Object.getOwnPropertyDescriptor(obj, prop)
obj is the source object, and prop is the property name that needs to be viewed; the keys included in the result may include configurable, enumerable, writable, get, set, and value.
const obj = { get es8() { return 888; } }; Object.getOwnPropertyDescriptor(obj, 'es8'); // { // configurable: true, // enumerable: true, // get: function es8(){}, //the getter function // set: undefined // }
Trailing commas in function parameter lists and calls
This feature allows us to add trailing commas when defining or calling functions without reporting an error :
function es8(var1, var2, var3,) { // ... } es8(10, 20, 30,);
Asynchronous function
ES8 allows the use of async/await syntax to define and execute asynchronous functions. The async keyword will return a certain AsyncFunction object; in the internal implementation, although the implementation principles of asynchronous functions and iterators are similar, they will not be converted into iterator functions:
function fetchTextByPromise() { return new Promise(resolve => { setTimeout(() => { resolve("es8"); }, 2000); }); } async function sayHello() { const externalFetchedText = await fetchTextByPromise(); console.log(`Hello, ${externalFetchedText}`); // Hello, es8 } sayHello(); console.log(1); sayHello(); console.log(2); // 调用结果 1 // immediately 2 // immediately Hello, es8 // after 2 seconds
Shared Memory and atomic operations
Shared memory allows multiple threads to read and write data concurrently, while atomic operations can perform concurrency control to ensure the sequential execution of multiple competing threads. This section introduces the new constructor SharedArrayBuffer and the namespace object Atomics that contains static methods. The Atomic object is similar to Math. We cannot create its instance directly, but can only use the static methods it provides:
add /sub - Add or subtract a value at a certain position
and / or /xor - Perform bit operations
load - Get the value
##
The above is the detailed content of Overview of the latest ES8 features. For more information, please follow other related articles on the PHP Chinese website!

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version
Recommended: Win version, supports code prompts!

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
