zoukankan      html  css  js  c++  java
  • 近期前端复习笔记0523

    01 typeof 

    参考:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/typeof

    语法:

    typeof XXXX(XXXX表达式)
     or
    typeof (XXXX)

    返回:

    返回一个字符串(表示未经计算的操作数的类型),常用于判断数据类型(只能区分基本类型,即 “number”,”string”,”undefined”,”boolean”,”object” 五种。对于数组、对象来说,其关系错综复杂,使用 typeof 都会统一返回 “object” 字符串。)

    注意:

    null 返回 "object",
    [] 返回 "object"// 数组被认为是一个对象

    02 instanceof 

    参考:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/instanceof

    语法:

    XXXX(要检测的对象)instanceof XXXX(XX构造函数)

    返回:

    返回 bool,常用于测试一个对象在其原型链中是否存在一个构造函数的 prototype 属性

    注意

    var myString = new String();
    myString instanceof String; // 返回 true
    myString instanceof Object; // 返回 true

     

    03 toString.call()

    参考:https://www.cnblogs.com/wyaocn/p/5796142.html

    语法:

    toString.call(XXXX) 
    or
    Object.prototype.toString.call(XXXX)

    返回:

    返回一个字符串("[object Null]"表示null类型),常用于判断数据类型

    注意:

    自定义类型 返回 "[object Object]",
    eg.自定义类型如下
    function Person(name, age) {
        this.name = name;
        this.age = age;
    }
    var person = new Person("Rose", 18);
    Object.prototype.toString.call(arr); //”[object Object]” // 很明显这种方法不能准确判断person是Person类的实例,而只能用instanceof 操作符来进行判断(如下所示)
    console.log(person instanceof Person);//输出结果为true

     

    04 constructor

    参考:http://www.w3school.com.cn/jsref/jsref_constructor_array.asp

    语法:

    XXXX.constructor

    返回:

    返回对创建此对象的数组函数的引用,常用于判断数据类型

    注意:

    [] 返回 function Array() { [native code] }(用 if(test.constructor==Array) 判断)
    true 返回 function Boolean() { [native code] }(用 if(test.constructor==Boolean) 判断)

    05 其他判断数组方法

      1. Array.isArray() 用于确定传递的值是否是一个 Array。参考 https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray

      2. $.isArray()函数用于判断指定参数是否是一个数组。参考 http://www.runoob.com/jquery/misc-isarray.html




    *参考链接:
    https://blog.csdn.net/u011374890/article/details/50325323
    https://www.itcodemonkey.com/article/3440.html


  • 相关阅读:
    使用正向proxy 连调部署在k8s 中的spring cloud 中的rest服务
    goflow golang 的基于flow的编程库
    gvm golang 的多版本工具
    jvm-profiler 学习试用
    httpdiff http 请求diff 工具
    tengine lua 模块docker 镜像集成
    tengine 支持dubbo 的docker镜像
    openresty ngx.location.capture http2 问题
    systemd 使用rc.local 说明
    revel golang的全栈开发框架
  • 原文地址:https://www.cnblogs.com/aileLiu/p/9077949.html
Copyright © 2011-2022 走看看