当前位置:网站首页>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
边栏推荐
- RT-Thread的main线程“卡死”的一种可能原因及解决方案
- Togglebutton realizes the effect of switching lights
- Linux yum安装MySQL
- FTP file upload file implementation, regularly scan folders to upload files in the specified format to the server, C language to realize FTP file upload details and code case implementation
- Reading notes of difficult career creation
- STM32型号与Contex m对应关系
- Hutool中那些常用的工具类和方法
- Machine learning -- linear regression (sklearn)
- 电商数据分析--薪资预测(线性回归)
- Contiki source code + principle + function + programming + transplantation + drive + network (turn)
猜你喜欢

4、安装部署Spark(Spark on Yarn模式)

5G工作原理详解(解释&图解)

Characteristics, task status and startup of UCOS III

open-mmlab labelImg mmdetection

几个关于指针的声明【C语言】

荣耀Magic 3Pro 充电架构分析

IOT system framework learning

Word typesetting (subtotal)

Comparaison des solutions pour la plate - forme mobile Qualcomm & MTK & Kirin USB 3.0

RT-Thread的main线程“卡死”的一种可能原因及解决方案
随机推荐
Distribute wxWidgets application
2019 Tencent summer intern formal written examination
Variable star user module
选择法排序与冒泡法排序【C语言】
Wangeditor rich text reference and table usage
Unit test - unittest framework
B tree and b+ tree of MySQL index implementation
Keyword inline (inline function) usage analysis [C language]
Mysql database interview questions
I2C总线时序详解
Apprentissage automatique - - régression linéaire (sklearn)
Cannot change version of project facet Dynamic Web Module to 2.3.
Gallery's image browsing and component learning
The first simple case of GNN: Cora classification
Kaggle竞赛-Two Sigma Connect: Rental Listing Inquiries(XGBoost)
Variable parameter principle of C language function: VA_ start、va_ Arg and VA_ end
锂电池基础知识
[mrctf2020] dolls
Using LinkedHashMap to realize the caching of an LRU algorithm
Nodejs connect mysql