当前位置:网站首页>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>

转码器
边栏推荐
- Part II - C language improvement_ 11. Pretreatment
- Security team: Recently, there is an rce vulnerability in the COREMAIL email client of windows, which may lead to the disclosure of the private key of the wallet
- Thousands of tiles' tilt model browsing speeds up, saying goodbye to the embarrassment of jumping out one by one
- Six challenges facing enterprise data governance!
- ESMFold: AlphaFold2之后蛋白质结构预测的新突破
- Silicon Valley class lesson 5 - Tencent cloud object storage and course classification management
- Typescript stage learning
- 1. Configuration environment and project creation
- 力扣155题,最小栈
- org.yaml.snakeyaml.scanner. ScannerException: mapping values are not allowed here in ‘reader‘, line
猜你喜欢
电脑开机后内存占用过高(50%以上)

Dao:op token and non transferable NFT are committed to building a new digital democracy

Customer case | student education relies on observation cloud to create a new ecosystem of observable Smart Education

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

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

Why am I still writing articles on CSDN? A journey of accompanying learning.

Part II - C language improvement_ 11. Pretreatment

Machine learning notes - building recommendation system (3) six research directions of deep recommendation system

Product principles of non-financial decentralized application

np.transpose & np.expand_dims
随机推荐
【MySQL】CentOS 7.9安装、使用MySQL-5.7.39二进制版
Six challenges facing enterprise data governance!
[shader realizes shine effect _shader effect Chapter 3]
30、 Modern storage system (management database and distributed storage system)
Silicon Valley class lesson 7 - Tencent cloud on demand management module (2)
Re understand the life world and ourselves
Learn various details and thoughts of chatroom implementation in Muduo
Practical project: boost search engine
Hcia-r & s self use notes (21) STP technical background, STP foundation and data package structure, STP election rules and cases
P5469 [noi2019] robot (Lagrange interpolation, interval DP)
基本的SELECT语句
Security team: Recently, there is an rce vulnerability in the COREMAIL email client of windows, which may lead to the disclosure of the private key of the wallet
The memory occupation of the computer is too high after it is turned on (more than 50%)
The most classic Nature paper on Alzheimer's disease is suspected of fraud
Will the approval in advance affect the formal approval?
如何使用数据管道实现测试现代化
Tensorflow2.0 深度学习运行代码简单教程
Hcia-r & s self use notes (19) VLAN configuration and experiment, routing between VLANs
Go uses flag package to parse command line parameters
How can enterprises mitigate the security risks of Internet of things and industrial Internet of things