当前位置:网站首页>ES6 new symbol data type
ES6 new symbol data type
2022-07-27 09:12:00 【Cabbage 007】

1.Symbol Is a new data type , It means a unique ( Any two Symbol Types are not equal ),
Symbol Type is also a kind of basic type , adopt Symbol Function to get
const sym1 = Symbol()
const sym2 = Symbol()
console.log(sym1)
console.log(typeof sym1)
console.log(stm1 === sym2)

2.Symbol Function can take a string as an argument , Said to the Symbol Description of the example , Easy to distinguish
const sym3 = Symbol("name")
const sym4 = Symbol("address")
console.log(sym3)
console.log(sym4)
console.log(sym3 === sym4)

const sym3 = Symbol("name")
const sym4 = Symbol("name")
console.log(sym3)
console.log(sym4)
console.log(sym3 === sym4)

Symbol Equal or not Symbol() It doesn't matter to describe the information inside
3. If the description information is the same , Want to get two of the same Symbol() value , have access to Symbol.for()
const sym5 = Symbol.for("name")
const sym6 = Symbol.for("name")
console.log(sym5)
console.log(sym5 === sym6)

4. purpose : As an attribute of an object , The advantage is that attributes do not override ( Each from Symbol() Back to symbol Value is the only ,symbol As the identifier of the object property , This is the only purpose of this data type )
Be careful :
- Symbol Value as object property name , You can't use the dot operator .
- Symbol As property name , When traversing objects , This attribute will not appear in for .. in In circulation , And not by Object.keys() / Object.getOwnPropertyNames() / JSON.stringify() return
- adopt Object.getOwnPropertySymbol() Method , You can get all of the Symbol Property name
Object.getOwnPropertySymbol() It is used to get all of the specified objects Symbol Attribute name
const key1 = Symbol("tiger")
const key2 = Symbol("flag")
const o = {
a:1, b:2,
[key1]: 2022, [key2]:" A rich man " }
console.log(o[key1],o[key2])
// When variables are used as attributes of objects , Add variables as attributes through square brackets
Equivalent to : o[key1] = 2022 o[key2] = " A rich man "
console.log(Object.key(o) )
console.log(Object.getOwnPropertySymbols(0))

边栏推荐
- Explicit animation in arkui
- MATLAB data import -- importdata and load functions
- Common operations of BOM and compatible writing methods for obtaining page / window height, width and scrolling
- pollFirst(),pollLast(),peekFirst(),peekLast()
- Save Xiaoyi from Netease written test -- a typical application of Manhattan distance
- Qt中发送信号时参数为结构体或者自定义的类怎么办?
- Tensorflow package tf.keras module construction and training deep learning model
- ES6 new - string part
- Low cost, low threshold, easy deployment, a new choice for the digital transformation of 48 million + small and medium-sized enterprises
- Detailed explanation of two methods of Sqlalchemy
猜你喜欢

Pyqt5 rapid development and practice 4.1 qmainwindow

CUDA programming-02: first knowledge of CUDA Programming

一些实用、常用、效率越来越高的 Kubernetes 别名

B tree
![[micro service ~sentinel] sentinel dashboard control panel](/img/df/2fbe7826ea2b80a81d29351052ae28.png)
[micro service ~sentinel] sentinel dashboard control panel

Can "Gulangyu yuancosmos" become an "upgraded sample" of China's cultural tourism industry

CUDA Programming -03: thread level

Is the operation of assigning values to int variables atomic?

The execution sequence of async/await, macro tasks and micro tasks
![Software testing function testing a full set of common interview questions [function testing - zero foundation] essential 4-1](/img/1c/c1c1b15e502ee901a396840c01e84d.png)
Software testing function testing a full set of common interview questions [function testing - zero foundation] essential 4-1
随机推荐
Programming style
Detailed explanation of two methods of Sqlalchemy
Svg drawing curve
5g failed to stimulate the development of the industry, which disappointed not only operators, but also mobile phone enterprises
tensorflow包tf.keras模块构建和训练深度学习模型
Principle of flex:1
NPM and yarn update dependent packages
npm install报错 强制安装
As a VC, the auction house invested Web3 for the first time
Deep understanding of Kalman filter (3): multidimensional Kalman filter
Activation functions commonly used in deep learning
基于restful页面数据交互
1.3.1 Full Permutation Problem
Replace restricts the text box to regular expressions of numbers, numbers, letters, etc
js call和apply
C# 窗体应用常用基础控件讲解(适合萌新)
Tensorflow loss function
5G没能拉动行业发展,不仅运营商失望了,手机企业也失望了
网易笔试之解救小易——曼哈顿距离的典型应用
linux安装和远程连接mysql记录