JZTXT
  • 首页
  • Ai
  • Java
  • Python
  • Android
  • Mysql
  • JavaScript
  • Html
  • CSS

手写 typeof

发布时间 2023-05-29 22:42:41作者: 睡成蛆

function myTypeof(o,type){ const types = { 'string': true, 'number': true, 'symbol': true, 'bigint': true, 'function': true, 'boolean': true, 'undefined': true, 'null': false, 'array': false, 'object': false, } let k = Object.prototype.toString.call(o).toLowerCase().slice(8,-1) return types[k]?k:'object' }

    本栏目推荐文章
  • keyof和typeof的区别,连起来用会怎么样
  • typeof 主要用于检测基本数据类型,对于引用类型不大适用(因为所有引用类型的值都是 Object 的实例),只能知道是对象,而具体是什么类型的对象却无法判断。这时需要 instanceof 来判断到底是什么类型(普通Object类型、Array类型、Function类型、RegExp类型、Date类型,基本包装类型【包括:Boolean、Number、String类型】)的对象
  • typeof只能检测数据类型,而不能检测从数据类型中派生的其他类型,数组为object派生对象,所以依然返回object
  • typeof null是object可不是因为null是对象
  • typescript 报错 类型“Window & typeof globalThis”上不存在属性
  • C#知识点:特性实参必须是特性形参类型的常量表达式、typeof 表达式或数组创建表达式
  • typeof,instanceof
  • C# default 和 typeof
  • TypeScript关于keyof和typeof的用法分析
  • vue3+ts+vite enum keyof typeof a-table columns 里的使用 第十回
版权声明:本网站为非赢利性站点,本网站所有内容均来源于互联网相关站点自动搜索采集信息,相关链接已经注明来源。
联系我们