zoukankan      html  css  js  c++  java
  • JS中的各种检测

     1 //null 只在肯定返回null值时才使用null比较
     2 var element = document.getElementById("my-div");
     3 if (element === null) {
     4 
     5 };
     6 //string number boolean undefined
     7 var num = 123;
     8 if (typeof num === "number") {
     9 
    10 };
    11 
    12 /*
    13 检查引用值
    14 Date RegExp Error
    15 跨域的检查会有问题
    16 */
    17 if (value instanceof Date) {
    18 
    19 };
    20 
    21 //检查函数
    22 if (typeof myFunc === "function") {};
    23 //if (myFunct instanceof Function) {}; 不能跨域
    24 //浏览器函数 因为IE9之前返回有问题
    25 if ("querySelectorAll" in document) {};
    26 
    27 //检查数组
    28 function isArray(value){
    29     if (typeof Array.isArray === function) {
    30         return Array.isArray(value);
    31     }else{
    32         return Object.prototype.toString.call(value) === "[object Array]"; //IE9以下
    33     }
    34 }
    35 
    36 //检查属性
    37 if ("related" in object) {};
    38 if (object.hasOwnProperty("related")) {}; //仅检查实例对象
  • 相关阅读:
    @property
    UIViewController卸载过程(ios6.0以后)
    UIViewController卸载过程(ios6.0之前)
    UIViewController启动过程
    意淫原理,还是很有意思的
    协议
    多线程理解
    内存溢出与内存泄露
    jquery:实例方法
    计划,模型
  • 原文地址:https://www.cnblogs.com/goodspeed/p/3533806.html
Copyright © 2011-2022 走看看