当前位置:网站首页>ES6语法总结--上篇(基础篇)
ES6语法总结--上篇(基础篇)
2022-07-06 09:17:00 【阿波次嘚】
变量 let
1.存在块级作用域:变量在块级作用域中不会污染全局作用域。
2.不存在声明提升:变量只能在声明之后使用。
3.不影响作用域链:变量在作用域链中正常使用。
常量 const
1.声明时要赋初始值。
2.常量一般使用大写。
3.常量的值不能修改。
4.存在块级作用域。
5.数组和对象元素修改子元素不算是对常量修改(因为常量对应的地址并没有改变)。
解构赋值--提取数组和对象中的值并赋值给变量
简单结构
数组解构:
对象解构:注:解构时声明的变量要在对象中存在,解构时可以不考虑 对象key的顺序(把变量a,b换位置也可以正常解构)
复杂结构
对象的复杂结构:
起别名:
模板字符串 一对反引号 支持输出换行
用于变量拼接
用于dom拼接
对象简化写法--如果对象中的属性名和属性值相同,可以简化书写
省略属性值
省略匿名函数
箭头函数 =>
写法


this
this指向的是函数声明时所在作用域并且不会被改变。
箭头函数的this
普通函数的this
注意:
1.箭头函数不能作为构造实例化对象
2.不能使用arguments变量
箭头函数的使用场景
适用于:与this无关的回调,如:定时器、数组方法
不适用于: 事件回调(因为this指向不正确)、对象中声明方法
参数默认值
习惯把带有初始值的形参放到最后书写
基本写法

结合解构赋值 并赋初始值
rest参数 获取函数实参
注:...args要放到参数最后
展开运算符(扩展运算符) 将数组转逗号分割的字符串
应用场景
1.数组合并
2. 数组克隆--深拷贝
3. 伪数组转数组 (dom对象、arguments等)
技术参考:b站 – 【尚硅谷】 推荐大家去看
https://www.bilibili.com/video/BV1uK411H7on?p=1&vd
边栏推荐
- Dead loop in FreeRTOS task function
- 几个关于指针的声明【C语言】
- Fashion-Gen: The Generative Fashion Dataset and Challenge 论文解读&数据集介绍
- IOT system framework learning
- Mall project -- day09 -- order module
- Basic use of pytest
- ESP8266使用arduino连接阿里云物联网
- Principle and implementation of MySQL master-slave replication
- 高通&MTK&麒麟 手機平臺USB3.0方案對比
- Selective sorting and bubble sorting [C language]
猜你喜欢

ToggleButton实现一个开关灯的效果

Cannot change version of project facet Dynamic Web Module to 2.3.

Unit test - unittest framework

E-commerce data analysis -- User Behavior Analysis
![[yarn] CDP cluster yarn configuration capacity scheduler batch allocation](/img/85/0121478f8fc427d1200c5f060d5255.png)
[yarn] CDP cluster yarn configuration capacity scheduler batch allocation

RT-Thread 线程的时间片轮询调度

JS object and event learning notes
![[CDH] cdh5.16 configuring the setting of yarn task centralized allocation does not take effect](/img/e7/a0d4fc58429a0fd8c447891c848024.png)
[CDH] cdh5.16 configuring the setting of yarn task centralized allocation does not take effect

Wangeditor rich text reference and table usage

MP3mini播放模块arduino<DFRobotDFPlayerMini.h>函数详解
随机推荐
Redis interview questions
STM32型号与Contex m对应关系
Mysql的索引实现之B树和B+树
SQL time injection
RT-Thread的main线程“卡死”的一种可能原因及解决方案
Analysis of charging architecture of glory magic 3pro
Some concepts often asked in database interview
RT-Thread API参考手册
Détails du Protocole Internet
荣耀Magic 3Pro 充电架构分析
树莓派 轻触开关 按键使用
OSPF message details - LSA overview
Detailed explanation of express framework
Stage 4 MySQL database
Funny cartoon: Programmer's logic
JS object and event learning notes
arduino获取随机数
Small L's test paper
小天才电话手表 Z3工作原理
RT-Thread 线程的时间片轮询调度