zoukankan      html  css  js  c++  java
  • 判断js中的类型

    判断js中的类型:

    alert(Object.prototype.toString.apply([1,2]));    //"[object Array]"
    alert(Object.prototype.toString.apply('str'));    //"[object String]"
    alert(Object.prototype.toString.apply(1));       //"[object Number]"
    alert(Object.prototype.toString.apply(null));     //"[object Null]"
    alert(Object.prototype.toString.apply());         //"[object Undefined]"
    alert(Object.prototype.toString.apply(function(){}));      //"[object Function]"
    alert(Object.prototype.toString.apply(true))     //"[object Boolean]"
    alert(Object.prototype.toString.apply(new Object()));     //"[object Object]"


    function aa(){
    console.log("aa测试用例");
    }
    var b={};
    //aa.call(b); //相当于b.aa(),将aa()方法赋给b调用。
    aa.apply(b); //相当于b.aa(),将aa()方法赋给b调用。
     
     
    patientsDirection = [{ name: '入病房', clickstatus: false }, { name: '走廊', clickstatus: false },
    { name: '补液室', clickstatus: false }, { name: '手术室', clickstatus: false },
    { name: 'DSA室', clickstatus: false }, { name: '入ICU', clickstatus: false },
    { name: '自动离院', clickstatus: false }, { name: '好转离院', clickstatus: false },
    { name: '死亡', clickstatus: false }, { name: '转院', clickstatus: false },
    { name: '诊室', clickstatus: false }, { name: '留观', clickstatus: false }];

    console.log(typeof patientsDirection,patientsDirection instanceof Array,Object.prototype.toString.call(patientsDirection)==="[object Array]");
    console.log(typeof(Object.prototype.toString.apply([1,2])));
     
    sometimes the hardest part isn't letting go,but rather start over
  • 相关阅读:
    Thinkphp 控制器
    Thinkphp 框架基础
    smarty练习:考试系统
    smarty 自定义函数
    smarty 变量调节器
    python 格式化的三种方法
    python 随机生成汉字
    python中的and和or用法
    pytest 运行用例报错:unknown hook 'pytest_namespace' in plugin <module 'allure.pytest_plugin'
    Jenkins安装插件报错:该Jenkins实例似乎已离线
  • 原文地址:https://www.cnblogs.com/zhumeiming/p/9628275.html
Copyright © 2011-2022 走看看