In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail what is new in JavaScript6, and the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
What's new in JavaScript 6? Let's take a look at some new features of JavaScript 6.
Let, const (used to define block-local variables), function in the process of a program
Deconstruction: let {x, y} = pt; let [s, v, o] = triple ()
(provided that let pt = {XRV 2, YRV Rue 5})
Default parameter value: function f (x, yearly 1, zonal 0) {... }
Other parameters: function g (I, j,... r) {return r.slice (I, j);}
(no longer need to use arguments).
Data expansion: let a = [0Magi 1je 2jue 3], o = new Something (.. a); It can also be used for array literals: [1,... array, 4].
Object abbreviation:
Let one = 1; {one, func_one () {return 1;}, ['key' + one]: 1}.
Function abbreviation (a) = > a * a has the same effect.
(function (a) {return a * a;}) .bind (this)
Map, set: let m = new Map (); m.set (key, value); m.has (key); m.get (key).
It also includes .clear (), .delete (), .forEach (), .keys ().
Weak map: let map = new WeakMap (). Use it when there is a circular reference. Similarly, new WeakSet ().
Promise: new Promise ((resolve, reject) = > {… }).
When promise.then (value = > {… }), resolve (valueOrPromise) returns the promised value (or a new promise, forming a chained call)
When promise.then (...) .then (…) .catch (error = > {... }) when reject (new Error (…)) Interrupt promise
Fast promise creation: Promise.resolve (value), Promise.reject (error).
Iteration: Promise.all (listOfPromises) .then (listOfValues = > …)
Promise.race (listOfPromises) .then (valueThatResolvedFirst = > …)
Agent: let obj = new Proxy (proto, handler).
To put it simply: use the elements of the class object for overloading (can bring all accessible attributes.)
Generator: function* gen () {yield 1; yield 2;}
In fact, gen () returns an object that contains the next () function.
Loop: for (var [key, val] of items (x)) {alert (key +','+ val);}.
Extends, super, and static are used in class definitions:
Class Point extends Base {constructor (X return Math.sqrt y) {super (); this [px] = x, this [py] = y; this.r = function () {return Math.sqrt (x + y);}} get x () {return this [px];} get y () {return this [py] } proto_r () {return Math.sqrt (This [PX] * this [px] + this [py] * this [py]);} equals (p) {return this [px] = p [px] & & this [py] = p [py];}}
A Symbol object that creates a private key that can be used in map and classes (private members)
Members).
Let a = Map (); {let k = Symbol (); a.set (k, 'value'); / / here you can access and set' value', such as a.get (k). } / / not here, k is invisible.
Modularity:
Module math {export function sum (x, y) {return x + y;} export var pi = 3.141593;} import {sum, pi} from math; alert (sum (pi,pi))
Templated string: can have multiple lines and embed variables.
`You are ${age} years old.`.
/ / the multi-line string re`line1: (words) * line2:\ w+ `/ / It desugars to: re ({raw:'line1: (words) *\ nline2:\ wrestling, cooked:'line1: (words) *\ nline2:\ wrestling'}) this is the end of what is new in JavaScript6. I hope the above content can be helpful to you and learn more. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.