首页 > 其他分享 >4.内部属性[[Class]]是什么

4.内部属性[[Class]]是什么

时间:2023-07-14 23:15:12浏览次数:52  
标签:object 内部 Object toString prototype Class2 Class 属性

4. 内部属性 [[Class]] 是什么?

所有 typeof 返回值为 "object" 的对象(如数组)都包含一个
内部属性 [[Class]]
(我们可以把它看作
一个内部的分类,而非
传统的面向对象意义上的类
)。

这个属性
无法直接访问,一般通过 Object.prototype.toString(..) 来查看。

例如:

Object.prototype.toString.call( [1,2,3] );
// "[object Array]"

Object.prototype.toString.call( /regex-literal/i );
// "[object RegExp]"

我们自己创建的类就不会有这份特殊待遇,
因为 toString() 找不到 toStringTag 属性时只好返回默认的 Object 标签

// 默认情况类的[[Class]]返回[object Object]
class Class1 {}
Object.prototype.toString.call(new Class1()); // "[object Object]"
// 需要定制[[Class]]
class Class2 {
  get [Symbol.toStringTag]() {
    return "Class2";
  }
}
Object.prototype.toString.call(new Class2()); // "[object Class2]"

标签:object,内部,Object,toString,prototype,Class2,Class,属性
From: https://www.cnblogs.com/zhuoss/p/17555282.html

相关文章

  • 105.什么是SamesiteCookie属性
    105.什么是SamesiteCookie属性?SamesiteCookie表示同站cookie,避免cookie被第三方所利用。将Samesite设为strict,这种称为严格模式,表示这个cookie在任何情况下都不可能作为第三方cookie。将Samesite设为Lax,这种模式称为宽松模式,如果这个请求是个GET请求,并......
  • cpp class constructor initialize list and override cout
    //book.h#pragmaonce#include<iostream>classbook{public:intidx;std::uint64_tid;std::stringauthor;std::stringcontent;std::stringcomment;std::stringisbn;std::stringsummary;std::stringtopic;boo......
  • 【Azure Redis】Azure Redis添加了内部虚拟网络后,其他区域的主机通过虚拟网络对等互连
    问题描述跨区域无法访问AzureRedis服务,Redis启用了Network并设置在一个VNET中,现在客户端部署在另一个区域数据中心中,两个数据中心区域使用VNETPeer(对等互连)访问。但是为什么不能访问Redis服务呢? 问题解答根据AzureRedis的官方介绍,因为Redis服务使用了Azure负载均衡,并且......
  • 配置问题-Error creating bean with name 'user' defined in class path resource [be
    正在学习IoC使用的jdk版本为jdk17依赖为:<dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>6.0.6</version></dependen......
  • maven打包repackage failed: Unable to find main class
    maven打包提示这个问题。原因:主项目pomxml文件中,不需要<build>打包的配置,只需要在有入口类的模块pom.xml配置好<build><build><finalName>${project.artifactId}</finalName><plugins><plugin><groupId>org.......
  • Spring Boot Admin 配置属性
     SpringBootAdminServer配置属性详解属性描述默认值spring.boot.admin.context-path上下文路径在应为AdminServer的静态资产和API提供服务的路径的前面加上前缀。相对于Dispatcher-Servlet/spring.boot.admin.monitor.status-interval更新client端状态的时间......
  • java调用class类
    Java调用class类的流程下面是Java调用class类的流程,可以用表格展示步骤:步骤描述步骤1导入需要调用的类步骤2创建类的实例步骤3调用类的方法或访问类的属性接下来,我将详细解释每一步需要做什么,以及提供相应的代码示例,每一段代码都会有注释解释其意义。步骤......
  • Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass
    pom文件中JDK是1.8项目的jdk17只需要统一一下jdk即可......
  • 删除img标签里的width和height属性,并在img标签前后加一个br标签
    #提取img标签tree_img=etree.HTML(content)width=tree_img.xpath('//img//@width')[0]height=tree_img.xpath('//img//@height')[0]#替换掉width=,和height=......
  • Paper Reading: Self-paced Ensemble for Highly Imbalanced Massive Data Classifica
    目录研究动机文章贡献分类硬度分布分类硬度的定义分类硬度的优点分类硬度视角下的样本类型本文方法自定步速欠采样硬度协调自定步速因子算法定义实验结果合成数据集实验数据集和实验设置合成数据实验结果类重叠下的鲁棒性真实数据集实验数据集和实验设置真实数据实验结果和重采样......