返回一个 boolean 值,指出对象是否是特定类的一个实例。
result = object instanceof class
参数
result
必选项。任意变量。
object
必选项。任意对象表达式。
class
必选项。任意已定义的对象类。
说明
如果 object 是 class 的一个实例,则 instanceof 运算符返回 true。如果 object 不是指定类的一个实例,或者 object 是 null,则返回 false。
示例
下面的例子举例说明了 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));
要求
版本 5
请参阅
运算符优先级 | 运算符总结
闽公网安备 35060202000074号