当前位置: 首页 > news >正文

北京中交建设工程咨询有限公司网站成都网站建设sntuu

北京中交建设工程咨询有限公司网站,成都网站建设sntuu,当前最好用的wordpress主题,网站制作完成后为了js中经常用到数据类型检查#xff0c;常用的类型检查方法有typeof、instanceof、constructor、Object.prototype.toString.call等#xff0c;现在逐一介绍一下。 js中数据类型总体上分为二大类#xff1a;基本类型(原始数据类型)和引用类型#xff0c;其中 基本类型又分为…js中经常用到数据类型检查常用的类型检查方法有typeof、instanceof、constructor、Object.prototype.toString.call等现在逐一介绍一下。 js中数据类型总体上分为二大类基本类型(原始数据类型)和引用类型其中 基本类型又分为常用的 string、number、boolean、null、undefined、symbol、BigInt这些类型 引用类型是除去基本类型外的比如常用的Array、Object这些 一、typeof 1. 使用typeof判断基本类型 const str testme typeof str // stringconst num 123 typeof num // numberconst bol true typeof bol // booleanconst nu null type nu // objecttypeof undefVar // undefinedconst sy Symbol(a) typeof sy // symbolconst bi BigInt(12345678910111213) typeof bi // bigint2. 使用typeof判断引用类型const arr [1,5,7] typeof arr // objectconst obj {a:3} typeof obj // objectfunction Man(name,age) {this.name namethis.age age } typeof Man // functionconst man new Man(Lily, 12) typeof man // object 二、instanceof 使用方法:  A instanceof B 主要是确认B.prototype属性是否在A的原型链上如果一直顺着原型链找到Object.prototype还是没找到结果就返回false。主要用来判断引用数据类型的 const arr [1,5,7] arr instanceof Array // trueconst obj {a:3} obj instanceof Object // trueobj instanceof Array // falsefunction Man(name,age) {this.name namethis.age age }Man instanceof Function // trueconst man new Man(Lily, 12) man instanceof Object // true 三、constructor A.constructor主要可以返回A对应的构造函数 const str testme str.constructor String // trueconst num 123 num.constructor Number // trueconst bol true bol.constructor Boolean // trueconst arr [1,5,7] arr.constructor Array // trueconst obj {a:3} obj.constructor Object // truefunction Man(name,age) {this.name namethis.age age }Man.constructor Function // trueconst man new Man(Lily, 12) man.constructor Man // true但是像 null、undefined这种就调用不了constructor判断数据类型了 四、Object.prototype.toString.call Object.prototype.toString.call方法返回各数据类型的[object xxx]形式 const str testme Object.prototype.toString.call(str) // [object String]const num 123 Object.prototype.toString.call(num) // [object Number]const bol true Object.prototype.toString.call(bol) // [object Boolean]const sy Symbol(a) Object.prototype.toString.call(sy) // [object Symbol]const bi BigInt(12345678910111213) Object.prototype.toString.call(bi) // [object BigInt]Object.prototype.toString.call(null) // [object Null]Object.prototype.toString.call(undefined) // [object Undefined]const arr [1,5,7] Object.prototype.toString.call(arr) // [object Array]const obj {a:3} Object.prototype.toString.call(obj) // [object Object]function Man(name,age) {this.name namethis.age age }Object.prototype.toString.call(Man) // [object Function]const man new Man(Lily, 12) Object.prototype.toString.call(man) // [object Object] 可以看出Object.prototype.toString.call方法判断的数据类型更广。 去掉Object.prototype.toString.call方法返回结果中的[object只保留具体类型 function getType(data) {return Object.prototype.toString.call(data).replace(/\[object\s(.)\]/, $1 ).toLowerCase() }const str testme getType(str) // stringconst num 123 getType(num) // numberconst bol true getType(bol) // booleanconst sy Symbol(a) getType(sy) //symbolconst bi BigInt(12345678910111213) getType(bi) // bigIntgetType(null) // nullgetType(undefined) // undefinedconst arr [1,5,7] getType(arr) // arrayconst obj {a:3} getType(obj) // objectfunction Man(name,age) {this.name namethis.age age }getType(Man) // functionconst man new Man(Lily, 12) getType(man) // object
http://www.huolong8.cn/news/21260/

相关文章:

  • 手机网站建设服务合同范本做网站下载那个数据库好
  • 网站开发实验报告开源社区的发展前景
  • flash网站建设技术是什么怎么申请免费国内免费网站
  • 阿里云怎么上传网站外链工具在线
  • 做吃的网站wordpress nginx 固定链接
  • 手机版万能视频提取器乐陵seo优化推广
  • 昆明公司网站制作查征信怎么查 个人免费查询
  • vultr 做网站mvc做的游戏网站
  • 利用网络媒体营销来做电商网站论文广州 环保 凡人网站建设
  • 安卓手机建设网站怎么注册一个公司网站
  • 电商网站开发数据库表个人网页设计作品html
  • 建筑之家绵阳seo
  • 网站到期请续费网站开发东莞
  • 北京市优化网站网站建设维护面试
  • 呼市网站优化网页设计页面图片
  • 百度站长网站提交宁波有做网站的地方吗
  • 校园网站html模板自己创建公众号免费吗
  • 网站开发的心得内蒙古建设安全监督站的网站
  • 怎么开通个人网站江宁住房和城乡建设局网站
  • 沧州企业网站制作直播网站排名
  • 南通通明建设监理有限公司网站如何设计一个简洁的logo
  • 建设零食网站的可行性上海响应式网页建设
  • 做网站带源码软件-dwdw网站制作的源代码
  • 海珠网站建设制作server2008部署网站
  • 网站如何做担保交易平台珠宝网站设计方案
  • 建设部监理工程师报考网站泉州市建设工程质量监督站网站
  • 湛江赤坎海田网站建设招聘wordpress加载很慢
  • 盘锦做网站多少钱广州seo网络推广员
  • 建设vip视频解析网站违法吗wordpress 流量
  • 制作网站公司哪里好网站估值怎么做