之前我都是使用typeof,后来发现它的判断有局限,例如(){}
obeject.p.toString.call()解决了

obj.toString()的结果和Object.prototype.toString.call(obj)的结果不一样,这是为什么?

这是因为toString为Object的原型方法,而Array 、Function等类型作为Object的实例,都重写了toString方法。不同的对象类型调用toString方法时,根据原型链的知识,调用的是对应的重写之后的toString方法(Function类型返回内容为函数体的字符串,Array类型返回元素组成的字符串.....),而不会去调用Object上原型toString方法(返回对象的具体类型),所以采用obj.toString()不能得到其对象类型,只能将obj转换为字符串类型;因此,在想要得到对象的具体类型时,应该调用Object上原型toString方法。

1.6判断类型toString.call()的更多相关文章

  1. SpringMVC上传文件以流方式判断类型附常用类型

    // 此类中判断类型所截取的byte 长度暂不确定,请使用者测试过使用 package com.tg.common.other; import com.tg.common.tginterface.TG ...

  2. js判断类型的方法

    //判断类型 var arr=[]; Object.prototype.toString.call(arr)=='[object Array]' //判断是否是包含关系 function elCont ...

  3. Java的equals方法,首先要判断类型是否相同

    如下代码,Long 和Integer 进行比较: Integer aa = 1; Long bb= 1L; System.out.println(aa.equals(bb)); 输出为:false 查 ...

  4. obj.getClass() == Person.class 用于判断类型

    obj.getClass() == Person.class  用于判断类型

  5. laravel where筛选会判断类型吗?

    laravel where筛选会判断类型吗? laravel where筛选会判断类型吗? laravel where筛选会判断类型吗? 这个说会判断不对,说不会判断也不对. 当字符串'1'和数值1是 ...

  6. python继承,判断类型,多态

    1.python中继承 如果已经定义了Person类,需要定义新的Student和Teacher类时,可以直接从Person类继承: class Person(object): def __init_ ...

  7. php 基础 判断类型

    八.PHP中判断类型 is_bool():判断是否是布尔型 is_int().is_integer()和 is_long():判断是否为整型. is_float().is_double()和 is_r ...

  8. js判断类型方法

    在JavaScript中,有5种基本数据类型和1种复杂数据类型,基本数据类型有:Undefined, Null,Boolean, Number和String:复杂数据类型是Object,Object中 ...

  9. js判断类型的四种方法

    typeof:使用typeof可以很方便的判断六种类型:undefined.boolean.string.number.object.function 数组和null会被判断为object类型 ins ...

随机推荐

  1. OpenResty 实现项目的灰度发布

    1.安装 openresty 依赖模块: [root@Centos opt]# yum -y install pcre-devel openssl openssl-devel postgresql-d ...

  2. 011、Java中将范围大的数据类型变为范围小的数据类型

    01.代码如下 package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  3. 学生选课数据库MySQL语句练习题45道

    1. 查询Student表中的所有记录的Sname.Ssex和Class列. select Sname,Ssex,Class from Student;2. 查询教师所有的单位即不重复的Depart列 ...

  4. setTimeout的异步

    http://www.cnblogs.com/littledu/articles/2607211.html http://www.cnblogs.com/rubylouvre/archive/2009 ...

  5. 吴裕雄--天生自然java开发常用类库学习笔记:正则表达式

    public class RegexDemo01{ public static void main(String args[]){ String str = "1234567890" ...

  6. Rabbitmq之高级特性——百分百投递消息&消息确认模式&消息返回模式实现

    rabbitmq的高级特性: 如何保障消息的百分之百成功? 要满足4个条件:生产方发送出去,消费方接受到消息,发送方接收到消费者的确认信息,完善的消费补偿机制 解决方案,1)消息落库,进行消息状态打标 ...

  7. 【LeetCode】重新安排行程

    [问题]给定一个机票的字符串二维数组 [from, to],子数组中的两个成员分别表示飞机出发和降落的机场地点,对该行程进行重新规划排序.所有这些机票都属于一个从JFK(肯尼迪国际机场)出发的先生,所 ...

  8. 【Leetcode】交替打印FooBar

    [问题]我们提供一个类: class FooBar { public void foo() { ; i < n; i++) { print("foo"); } } publi ...

  9. plsql调用执行存储过程

    参考 https://www.cnblogs.com/enjoyjava/p/9131169.html ------------------------------------------------ ...

  10. [LeetCode] 932. Beautiful Array 漂亮数组

    For some fixed N, an array A is beautiful if it is a permutation of the integers 1, 2, ..., N, such ...