当前位置:网站首页>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 keySymbols are immutable and unique.
let sym2 = Symbol("key");let sym3 = Symbol("key");sym2 === sym3; // false, symbols are uniqueLike 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.
边栏推荐
- 适配器模式适配出栈和队列及优先级队列
- php组件漏洞
- 程序员的浪漫七夕
- R language time series data arithmetic operation: use the log function to log the time series data, and use the diff function to calculate the successive difference of the logarithmic time series data
- 如何安装dosbox(pycharm详细安装教程)
- 斯皮尔曼相关系数
- 超赞!发现一个APP逆向神器!
- 行为型模式-模板方法模式
- LayaBox---TypeScript---模块
- 你认同这个观点吗?大多数企业的数字化都只是为了缓解焦虑
猜你喜欢
随机推荐
R语言ggplot2可视化:使用ggpubr包的ggbarplot函数可视化水平柱状图(条形图)、使用orientation参数设置柱状图转置为条形图
3D激光slam:LeGO-LOAM---地面点提取方法及代码分析
LayaBox---TypeScript---Iterator and generator
同样做软件测试,和月收入 3W 的学弟聊了一晚上,我彻底崩溃了
wireshark的安装教程(暖气片安装方法图解)
Rust 从入门到精通03-helloworld
只问耕耘,不问收获,其实收获却在耕耘中
The ggline function of the R language ggpubr package visualizes grouped line graphs, the add parameter is mean_se and dotplot to visualize line graphs of different level averages, and adds error bars
3年测试在职,月薪还不足2w,最近被裁员,用亲身经历给大家提个醒...
STL中list实现
瑞萨RZ/G2L处理器详细测评
程序员的浪漫七夕
练习-17
链表的实现
8月份的.NET Conf 活动 专注于 .NET MAUI
38岁女儿不恋爱没有稳定工作老母亲愁哭
iNFTnews | Seeing the two sides of the metaverse, what is the true Internet and the Internet of value?
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
如何安装dosbox(pycharm详细安装教程)
你认同这个观点吗?大多数企业的数字化都只是为了缓解焦虑








