javascript instanceof 操作符
javascript instanceof 操作符介绍
返回一个 Boolean 值,指出对象是否是特定类的一个实例。
result = object instanceof class
参数
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));
来源:
http://www.yesky.com/imagesnew/software/javascript/html/jsoprinstanceof.htm
加支付宝好友偷能量挖...