当前位置:网站首页>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.
边栏推荐
- QT专题:自定义部件
- 阿里巴巴 CTO 程立:开源是基础软件的源头!
- LayaBox---TypeScript---Iterator and generator
- LayaBox---TypeScript---Three slash instructions
- 软件测试岗位巨坑?阿里在职7年测试人告诉你千万别上当
- R语言ggpubr包的ggbarplot函数可视化分组柱状图、设置add参数为mean_se可视化不同水平均值的柱状图并为柱状图添加误差线(se标准误差)、position参数自定义分组柱状图分离
- 行为型模式-策略模式
- QT专题:事件机制event基础篇
- [Science of Terminology] For those difficult words about the integrated workbench, read this article to understand in seconds!
- npm ERR! 400 Bad Request - PUT xxx - Cannot publish over previously published version “1.0.0“.
猜你喜欢
随机推荐
iNFTnews | 看见元宇宙的两面,何谓全真互联网和价值互联网?
享年94岁,图灵奖得主、计算复杂性理论先驱Juris Hartmanis逝世
软件测试H模型
MSYS2 QtCreator Clangd 代码分析找不到 mm_malloc.h的问题补救
One Summer of Open Source | How to Quickly Integrate Log Modules in GO Language Framework
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详细安装教程)
身为程序猿——谷歌浏览器的这些骚操作你真的废吗!【熬夜整理&建议收藏】[通俗易懂]
LayaBox---TypeScript---Mixins
R language ggplot2 visualization: use the ggbarplot function of the ggpubr package to visualize the stacked bar plot, the lab.pos parameter specifies the position of the numerical label of the bar cha
qq邮箱日发5万邮件群发技术(qq邮箱怎样定时发送邮件)
LayaBox---TypeScript---Iterator and generator
周杰伦新歌发布,爬取《Mojito》MV弹幕,看看粉丝们都说的些啥!
QT专题:自定义部件
Unknown content monitoring
After 21 years of graduation, I switched to software testing. From 0 income to a monthly salary of over 10,000, I am really lucky...
QT专题:事件机制event基础篇
LayaBox---TypeScript---Module
armv7与armv8的区别(v8和w12的区别)
c#反射和特性