当前位置:网站首页>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.
边栏推荐
- LayaBox---TypeScript---JSX
- 如何安装dosbox(pycharm详细安装教程)
- Shell脚本实现多选DNS同时批量解析域名IP地址(新更新)
- LayaBox---TypeScript---高级类型
- 3 d laser slam: LeGO - LOAM - ground point extracting method and the analysis of the code
- 你好,我的新名字叫“铜锁/Tongsuo”
- 牛客网项目2.7开发注册功能 报错This application has no explicit mapping for /error......
- 软件测试之发现和解决bug
- 迭代器失效问题
- [Science of Terminology] For those difficult words about the integrated workbench, read this article to understand in seconds!
猜你喜欢

瑞萨RZ/G2L处理器详细测评

链表的实现

games202:三,实时环境光照IBL + PRT

This article takes you to understand the commonly used models and frameworks of recommender systems

You Only Hypothesize Once: 用旋转等变描述子估计变换做点云配准(已开源)

第十七章 Excel操作

yolov7创新点

8月份的.NET Conf 活动 专注于 .NET MAUI

带你认识40G单纤双向光模块-QSFP+ BiDi光模块

Linux system uninstall, install, upgrade, migrate clickHouse database
随机推荐
软件测试的基本理论知识(软件测试面试基础知识)
零代码工具推荐---HiFlow
第十六章 协程
LayaBox---TypeScript---高级类型
MSYS2 QtCreator Clangd 代码分析找不到 mm_malloc.h的问题补救
软件测试H模型
程序员的浪漫七夕
38岁女儿不恋爱没有稳定工作老母亲愁哭
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
小几届的学弟问我,软件测试岗是选11k的华为还是20k的小公司,我直呼受不了,太凡尔赛了~
Event object, do you know it well?
R语言ggplot2可视化:使用ggpubr包的ggbarplot函数可视化水平柱状图(条形图)、使用orientation参数设置柱状图转置为条形图
LayaBox---TypeScript---Decorator
WPF 截图控件之文字(七)「仿微信」
LayaBox---TypeScript---Mixins
Rust 从入门到精通03-helloworld
第十五章 多线程
利用二维数据学习纹理三维网格生成(CVPR 2020)
The R language uses the rollapply function in the zoo package to apply the specified function to the time series in a rolling manner and the window moves, and set the align parameter to specify that t
Geoffery Hinton:深度学习的下一个大事件