当前位置:网站首页>LayaBox---TypeScript---Symbols
LayaBox---TypeScript---Symbols
2022-08-02 10:21:00 【Gragra】
Table of Contents
1.Introduction
As of ECMAScript 2015, symbol
is a new native type, just like number
and string
.
symbol
is created with the Symbol
constructor.
let sym1 = Symbol();let sym2 = Symbol("key"); // optional string key
Symbols are immutable and unique.
let sym2 = Symbol("key");let sym3 = Symbol("key");sym2 === sym3; // false, symbols are unique
Like strings, symbols can also be used as keys for object properties.
let sym = Symbol();let obj = {[sym]: "value"};console.log(obj[sym]); // "value"
Symbols can also be combined with computed property name declarations to declare object properties and class members.
const getClassNameSymbol = Symbol();class C {[getClassNameSymbol](){return "C";}}let c = new C();let className = c[getClassNameSymbol](); // "C"
2. Well-known Symbols
TheSymbol.hasInstance method will be called by the instanceof operator.Constructor objects are used to identify whether an object is an instance of it.
Symbol.isConcatSpreadableBoolean value indicating that when Array.prototype.concat< is called on an object/span>, whether the array elements of this object can be expanded.
TheSymbol.iterator method is called by the for-of statement.Returns the default iterator for the object.
Symbol.match method, called by String.prototype.match.Regular expressions are used to match strings.
Symbol.replace method, called by String.prototype.replace, regular expressionThe formula is used to replace the matched substring in the string
Symbol.search method, called by String.prototype.search, regular expressionreturns the index of the matched part in the string.
Symbol.speciesThe function value, which is a constructor.Used to create derived objects.
Symbol.split method, called by String.prototype.split.Regular expressions are used to split strings.
TheSymbol.toPrimitive method, called by the ToPrimitive abstract operation, converts the object tothe corresponding raw value.
TheSymbol.toStringTag method is called by the built-in method Object.prototype.toString.Returns the default string description when the object is created.
Symbol.unscopables object, its own properties will be with scopeExcluded.
边栏推荐
- R语言使用ggpubr包的ggtexttable函数可视化表格数据(直接绘制表格图或者在图像中添加表格数据)、设置theme主题参数自定义表格中表头内容的填充色(使用colnames.style参数)
- Hello, my new name is "Bronze Lock/Tongsuo"
- Long battery life or safer?Seal and dark blue SL03 comparison shopping guide
- LayaBox---TypeScript---装饰器
- 众城优选系统开发功能
- 程序员的浪漫七夕
- 阿里CTO程立:阿里巴巴开源的历程、理念和实践
- R语言ggplot2可视化:使用ggpubr包的ggtexttable函数可视化表格数据(直接绘制表格图或者在图像中添加表格数据)、使用tbody_add_border为表格中的表头添加外侧框线
- DirectX修复工具增强版「建议收藏」
- LayaBox---TypeScript---模块解析
猜你喜欢
日元疲软令游戏机在日本变身“理财产品”:黄牛大赚
周鸿祎称微软抄袭 360 安全模式后发文否认;英特尔CEO基辛格回应市值被AMD超越:股价下跌是咎由自取|极客头条...
Linux system uninstall, install, upgrade, migrate clickHouse database
Hello, my new name is "Bronze Lock/Tongsuo"
阿里CTO程立:阿里巴巴开源的历程、理念和实践
第十六章 协程
List-based queuing and calling system
阿里巴巴 CTO 程立:开源是基础软件的源头!
只问耕耘,不问收获,其实收获却在耕耘中
Jay Chou's new song is released, crawl the "Mojito" MV barrage, and see what the fans have to say!
随机推荐
后管实现面包屑功能
3D激光slam:LeGO-LOAM---地面点提取方法及代码分析
Long battery life or safer?Seal and dark blue SL03 comparison shopping guide
如何封装微信小程序的 wx.request() 请求
3 d laser slam: LeGO - LOAM - ground point extracting method and the analysis of the code
[Science of Terminology] For those difficult words about the integrated workbench, read this article to understand in seconds!
全方位剖析Numpy中的np.diag源代码
Turning and anti-climbing attack and defense
软件测试岗位巨坑?阿里在职7年测试人告诉你千万别上当
LayaBox---TypeScript---高级类型
每日一题练习1-15
如何安装dosbox(pycharm详细安装教程)
3年测试在职,月薪还不足2w,最近被裁员,用亲身经历给大家提个醒...
How to choose a truly "easy-to-use, high-performance" remote control software
Smoothing of time series data in R language: smoothing time series data to remove noise using the dpill function and locpoly function of the KernSmooth package
转转反爬攻防战
Alibaba CTO Cheng Li: Alibaba Open Source History, Concept and Practice
iNFTnews | Seeing the two sides of the metaverse, what is the true Internet and the Internet of value?
LayaBox---TypeScript---装饰器
R语言使用ggpubr包的ggtexttable函数可视化表格数据(直接绘制表格图或者在图像中添加表格数据)、设置theme主题参数自定义表格中表头内容的填充色(使用colnames.style参数)