当前位置:网站首页>ES6 new feature (1): let command / const command / deconstruction assignment / symbol / set / weakset
ES6 new feature (1): let command / const command / deconstruction assignment / symbol / set / weakset
2022-04-21 18:20:00 【Hua Weiyun】
( One )let command
1.let The declared variable is valid only in the code block in which the variable is declared
contrast :
2.let It is not allowed to declare variables repeatedly in the same scope :
correct , Error in parentheses
3.let Declaration of global variables
// error
// correct
4. Scope to child scope
( Two ) const command
const Command is used to generate a constant , After constant is declared , The value cannot be changed . Others and let identical .
( 3、 ... and ) Deconstruct assignment
1. An array of deconstruction
Nested array deconstruction
Vacancy variable
Redundant variables
The default value is
2. Object to deconstruct
Can be nested
There can be default values
3. String deconstruction
4. Deconstruction of function parameters
Array in parameter 、 character string 、 The default value is 、 All vacancies support
( Four )Symbol
Symbol yes ES6 A new value type data , Represents a value that never repeats
( 5、 ... and )Set
Set and WeakSet The data structure is ES6 newly added .
It is very similar to arrays , however Set The members of the data structure are unique . Element cannot be duplicated .
In particular :Set Only one... Can be added to the NaN.
Set data structure :
As can be seen from the output , The key and key value are the same .
es5 New array in map and filter Method
map: The meaning of mapping , The mapping returns a new array , There is a return value ;filterArr: Return a new object
filter: Filter 、 Screening means ; There is a return value ; filterArr: Returns the filtered new array
( 6、 ... and )WeakSet
It is associated with Set Very similar , The value of an object cannot be duplicate , And Set Difference :
1.WeakSet Members can only be objects .
2. As WeakSet Members are all weakly referenced objects , That is, garbage collection mechanism does not consider WeakSet Reference to the object , in other words , If no other object references that object , Then the garbage collection mechanism will automatically reclaim the memory occupied by the object , Regardless of whether the object still exists in WeakSet In . What does this feature mean , Can't quote WeakSet Members of , therefore WeakSet It's not ergodic .
3. Use WeakSet The benefits of storing object instances are , Because it is a reference to an object instance , Will not be included in the memory recycling mechanism , So when deleting an instance , Don't have to consider weakset, There will be no memory leaks .
版权声明
本文为[Hua Weiyun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211813094067.html
边栏推荐
猜你喜欢

随笔小杂记(六)——tqdm进度条显示出现多余行

ansible简单使用示例

【网络】4G、5G频段汇总

【pytorch图像分类】ResNet网络结构

Easy to use example

Finally someone made it clear! It turns out that this is the global one-piece network technology with low delay

IoT平台如何实现业务配置中心

After fastjson is automatically upgraded to fastjson2, the idea development environment is normally printed into a jar package and an error exception POM is reported after publishing the generated env

靶机渗透练习79-Venom

刚拿的字节跳动offer“打水漂”
随机推荐
[small program] Alipay applet custom pull down refresh component
MYCAT horizontal sub table (E-R table)
靶机渗透练习70-DC2
Huawei cloud gaussdb (for influx) unveiling phase VI - hierarchical data storage
【NPJ|数字医药】医学影像的机器学习:方法学的失败和对未来的建议
WPF学习笔记——概述
Kubernetes详解(三)——Kubernetes集群组件
k-means,层次,EM聚类介绍
IoT平台如何实现业务配置中心
Target penetration exercise 71-dc3
包装类
【网络】4G、5G频段汇总
干货|app自动化测试之Appium WebView 技术原理
靶机渗透练习75-DC7
C语言进阶第48式:函数设计原则
TCP/IP协议
为拿几家大厂Offer,“闭关修炼
Target penetration exercise 74-dc6
You must understand and can understand microservice series 3: service invocation
String(一个特殊的数据类型)


