zoukankan      html  css  js  c++  java
  • JavaScript中instanceof运算符

    JavaScript中instanceof运算符是返回一个 Boolean 值,指出对象是否是特定类的一个实例。
    使用方法:
    result = object instanceof class
    其中result是必选项。任意变量。
    object是必选项。任意对象表达式。
    class是必选项。任意已定义的对象类。

    说明
    如果 object 是 class 的一个实例,则 instanceof 运算符返回 true。如果 object 不是指定类的一个实例,或者 object 是 null,则返回 false。

    JavaScript中instanceof运算符
    下面的例子举例说明了 instanceof 运算符的用法。
    function objTest(obj){
       var i, t, s = "";   // 创建变量。
       t = new Array();   // 创建一个数组。
       t["Date"] = Date;   // 填充数组。
       t["Object"] = Object;
       t["Array"] = Array;
          for (i in t)
          {
             if (obj instanceof t[i])   // 检查 obj 的类。
             {
                s += "obj is an instance of " + i + "\n";
             }
             else
             {
                s += "obj is not an instance of " + i + "\n";
             }
       }
       return(s);   // 返回字符串。
    }

    var obj = new Date();
    response.write(objTest(obj));
  • 相关阅读:
    POJ 2186 Popular Cows
    POJ 1364 King
    poj1811
    poj1404
    poj1781
    poj1386
    poj1442
    C#中调用IE打开某文档
    【观点】什么时候学习编程都不晚
    遍历DataTable内存数据的三种方法性能对比
  • 原文地址:https://www.cnblogs.com/weekend001/p/1643414.html
Copyright © 2011-2022 走看看