当前位置:网站首页>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.
边栏推荐
猜你喜欢
随机推荐
超赞!发现一个APP逆向神器!
MySql tens of millions of paging optimization, fast insertion method of tens of millions of data
Geoffery Hinton:深度学习的下一个大事件
利用二维数据学习纹理三维网格生成(CVPR 2020)
一款优秀的中文识别库——ocr
R language ggplot2 visualization: use the ggtexttable function of the ggpubr package to visualize tabular data (directly draw tabular graphs or add tabular data to images), use tbody_add_border to add
List-based queuing and calling system
8月份的.NET Conf 活动 专注于 .NET MAUI
Do you agree with this view?Most businesses are digitizing just to ease anxiety
Jay Chou's new song is released, crawl the "Mojito" MV barrage, and see what the fans have to say!
关于缓存数据的探讨
R language ggplot2 visualization: use the ggbarplot function of the ggpubr package to visualize the horizontal column chart (bar chart), use the orientation parameter to set the column chart to be tra
LayaBox---TypeScript---高级类型
Unknown content monitoring
Use compilation to realize special effects of love
TimerTask(addin timer语音)
LayaBox---TypeScript---模块解析
DirectX修复工具增强版「建议收藏」
38岁女儿不恋爱没有稳定工作老母亲愁哭
games202:三,实时环境光照IBL + PRT









