当前位置:网站首页>ES6新特性
ES6新特性
2022-07-26 22:33:00 【zpy66669】
前言
现在在使用的主流前端框架中,Vue.js等,都会使用到ES6的新特性
还是有java基础学起来很简单
let和const
- let,防止var定义的变量变成全局变量




- const,类似于java中的final关键字,不能被修改


字符串扩展
- includes() 返回布尔值,是否找到参数字符串
- startsWith() 返回布尔值,参数字符串是否在原字符串的头部(是否以xxx开头)
- endsWith() 返回布尔值,参数字符串是否在原字符串的尾部(是否结尾为xxx)
字符串模板`` 数字键盘一左边
结构表达式
ES6中允许按照一定模式从数组和对象中提取值,然后对变量进行赋值,这被称为解构
数组解构

对象解构

函数优化
函数参数默认值

箭头函数


map
接收一个函数,将原数组中的所有元素用这个函数处理后放入新数组返回

reduce
reduce()∶接收一个函数(必须)和一个初始值(可选)该函数接收两个参数∶
- 第一个参数是上一次reduce处理的结果
- 第二个参数是数组中要处理的下一个元素
reduce()会从左到右依次把数组中的元素用reduce处理,并把处理的结果作为下次reduce的第一个参数。如果是第一次,会把前两个元素作为计算参数,或者把用户指定的初始值作为起始参数
举例

扩展运算符
…,将一个数组转为用逗号分隔的参数序列

Promise
所i谓Promise,简单说就是一个容器,里面保存着某个未来才会结束的事件(通常是一个异步操作)的结果。从语法上说,Promise是一个对象,从它可以获取异步操作的消息。Promise提供统一的API,各种异步操作都可以用同样的方法进行处理。
我们可以通过Promlse的构造函数来创建Promise对象,并在内部封装一个异步执行的结果。

Set和Map数据结构
Set
本质和数组类似,相同元素会被忽略,和java中的Set集合类似

Map
本质是与Object类似的结构,不同在于,Object强制规定ket只能是字符串,而Map结构的key可以是任意对象
- Object是<String,object>
- Map是<object,object>

class
和java差不多,感觉不需要写
Generator函数 *
- Generatar 函故是ES6提供的一种异步综程解决方案,语法行为与传统函数完全不同
- Generator函数有两个特征:一是function命令与函数名之间有一个星号;二是函数体内部使用yield吾句定义不同的内部状态
<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())
//另一种方法
for(let v for h){
console.log(v)
}
</script>

转码器
边栏推荐
- Vector execution engine framework gluten announced the official open source and appeared at spark technology summit
- 百度网址收录
- Related functions of strings
- 【不积跬步无以至千里】统计日志指定时间段内的关键词
- Hcia-r & s self use notes (21) STP technical background, STP foundation and data package structure, STP election rules and cases
- The nature and proof of the center of gravity of [mathematics] tree
- 基于gRPC编写golang简单C2远控
- np.transpose & np.expand_dims
- TypeScript阶段学习
- Go uses flag package to parse command line parameters
猜你喜欢

Silicon Valley class lesson 6 - Tencent cloud on demand management module (I)

上千Tile的倾斜模型浏览提速,告别一块一块往外蹦的尴尬

Esmfold: a new breakthrough in protein structure prediction after alphafold2

会议OA之我的会议

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
![[shader realizes swaying effect _shader effect Chapter 4]](/img/ab/bdbc4a0f297541b532af81a49e2633.png)
[shader realizes swaying effect _shader effect Chapter 4]

ESMFold: AlphaFold2之后蛋白质结构预测的新突破

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

HCIA-R&S自用笔记(20)VLAN综合实验、GVRP

How to transfer the GPX data collected by CTI RTK out of KML and SHP with attributes for subsequent management and analysis
随机推荐
30、 Modern storage system (management database and distributed storage system)
C.Net timestamp and time conversion support time zone
Public cloud security and compliance considerations
Use Arthas to locate online problems
Hcia-r & s self use notes (23) DHCP
18. Opening and saving file dialog box usage notes
Pyqt5 how to set pushbutton click event to obtain file address
Will the approval in advance affect the formal approval?
百度网址收录
[postgresql]postgresqlg use generate_ Series() function completes statistics
Three person management of system design
Pre research of data quality management tools Griffin vs deequ vs great expectations vs quality
第二部分—C语言提高篇_11. 预处理
[Luogu] p2709 little B's inquiry
[shader realizes shine effect _shader effect Chapter 3]
After working for one year, I have some insights (written in 2017)
Learn various details and thoughts of chatroom implementation in Muduo
企业数据治理面临的六大挑战!
什么是 Base64 ?
Eureka basic use