当前位置:网站首页>New features of ES6
New features of ES6
2022-07-26 23:41:00 【zpy66669】
Preface
Now in the mainstream front-end framework ,Vue.js etc. , Will be used ES6 New features
Still have java Basic learning is very simple
let and const
- let, prevent var The defined variable becomes a global variable




- const, Be similar to java Medium final keyword , Cannot be modified


String extension
- includes() Returns a Boolean value , Is the parameter string found
- startsWith() Returns a Boolean value , Whether the parameter string is at the head of the original string ( Whether or not to xxx start )
- endsWith() Returns a Boolean value , Whether the parameter string is at the end of the original string ( Whether it ends with xxx)
String template `` Number pad one left 
Structure expression
ES6 Allows you to extract values from arrays and objects according to certain patterns , And then assign values to variables , This is called deconstruction
An array of deconstruction

Object to deconstruct

Function optimization
Function parameter defaults

Arrow function


map
Receive a function , All elements in the original array are processed with this function and put into the new array to return

reduce
reduce()∶ Receive a function ( must ) And an initial value ( Optional ) This function takes two arguments ∶
- The first parameter is the last time reduce Results of processing
- The second parameter is the next element in the array to be processed
reduce() The elements in the array will be used from left to right with reduce Handle , And treat the result as next time reduce The first parameter of . If it's the first time , The first two elements are taken as calculation parameters , Or take the initial value specified by the user as the starting parameter
give an example

Extension operator
…, Convert an array to a comma separated sequence of parameters

Promise
the i Predicate Promise, It's simply a container , It holds an event that will end in the future ( This is usually an asynchronous operation ) Result . grammatically ,Promise It's an object , From it you can get messages for asynchronous operations .Promise Provide uniform API, Various asynchronous operations can be handled in the same way .
We can go through Promlse Constructor to create Promise object , And encapsulate the result of an asynchronous execution inside .

Set and Map data structure
Set
The essence is similar to array , The same elements will be ignored , and java Medium Set Set similar

Map
The essence is with Object Similar structures , Difference is that ,Object A mandatory provision ket It can only be a string , and Map Structural key It can be any object
- Object yes <String,object>
- Map yes <object,object>

class
and java almost , I don't feel like writing
Generator function *
- Generatar Letter is ES6 It provides an asynchronous comprehensive solution , Grammatical behavior is totally different from traditional function
- Generator Functions have two characteristics : One is function There is an asterisk between the command and the function name ; The second is the internal use of the function body yield I define different internal states
<script>
function * hello(){
yield "hello"
yield "niuma"
yield "xigua"
yield "qnm"
return "sl"
}
let h = hello()
console.log(h.next())
console.log(h.next())
console.log(h.next())
console.log(h.next())
console.log(h.next())
// Another way
for(let v for h){
console.log(v)
}
</script>

Transcoder
边栏推荐
- Go uses flag package to parse command line parameters
- What is Base64?
- 嵌入式系统移植【8】——设备树和根文件系统移植
- MVC三层架构
- What are the use cases in the Internet of things industry in 2022?
- Part II - C language improvement_ 9. Linked list
- 30、 Modern storage system (management database and distributed storage system)
- 公有云安全性和合规性方面的考虑事项
- Three person management of system design
- 股票开户佣金是否可以调整?手机上开户安不安全
猜你喜欢

How to transfer the GPX data collected by CTI RTK out of KML and SHP with attributes for subsequent management and analysis

Science | University of Washington uses AI and structural prediction to design new proteins

Hcia-r & s self use notes (23) DHCP

Pytorch learning record (II): tensor

Sign up now | frontier technology exploration: how to make spark stronger and more flexible

04 traditional synchronized lock

第二部分—C语言提高篇_7. 结构体

Easily implement seckill system with redis! (including code)

Re understand the life world and ourselves
![[2016] [paper notes] differential frequency tunable THz technology——](/img/7e/71126950250997fc436a4ee730aee7.png)
[2016] [paper notes] differential frequency tunable THz technology——
随机推荐
Professor Ashe, a Chinese scientist, made a positive response to the suspected fake Nature paper
Question 141 of Li Kou: circular linked list
What is Base64?
MySQL 数据的导入
【面试:并发篇27:多线程:犹豫模式】
力扣141题:环形链表
Distributed lock and its implementation
第二部分—C语言提高篇_10. 函数指针和回调函数
04 traditional synchronized lock
Part II - C language improvement_ 12. Packaging and use of dynamic / precision Library
Part II - C language improvement_ 11. Pretreatment
Part II - C language improvement_ 10. Function pointer and callback function
MySQL random paging to get non duplicate data
2022.7.26-----leetcode.1206
Write golang simple C2 remote control based on grpc
会议OA之我的会议
SQL Basics
Interview questions of Bank of Hangzhou [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]
Cheaper than seals, with a large space for shape explosion. Is there really no match for 200000 or so? Chang'an's new "King fried" is cost-effective
【C语言】经典的递归问题