js运行时类型识别的例子
来源:互联网 发布:小猪cms最新版 编辑:程序博客网 时间:2024/06/05 09:42
<html>
<head>
<title>Example-5.7运行时类型识别</title>
</head>
<body>
<script>
<!--
/*这个函数扩展了Object原型方法,以支持对对象的类型进行更细粒度的判定。
*/
Object.prototype.InstanceOf = function(type)
{
try{
//typeof、constructor或者instanceof三个条件之一满足,就返回true,否则返回false
return typeof(this) == type || //通过typeof判断
this.constructor == type || //通过constructor判断
this instanceof type; //通过instanceof判断
}
catch(ex){
return false;
}
}
var a = new Object();
document.write(a.InstanceOf(Object)+ "<br/>"); //true
var b = "abc";
document.write(b.InstanceOf(String) + "<br/>"); //true
var c = new String("abc");
document.write(c.InstanceOf(String) + "<br/>"); //true
var d = new Array();
document.write(d.InstanceOf(Array)); //true
-->
</script>
</body>
</html>
上面这段代码是王者归来里面的代码,其中这一段我不是很理解: this instanceof type;
哪位朋友读懂,能给我留个言吗?
- js运行时类型识别的例子
- 验证运行时类型识别例子
- 运行时类型识别
- 运行时类型识别
- 运行时类型识别
- 运行时类型识别
- 运行时类型识别
- 运行时类型识别
- 运行时类型识别
- 运行时类型识别
- 运行时类型识别
- MFC的运行时类型识别
- 运行时类型识别(RTTI)
- RTTI 运行时类型识别
- 运行时类型识别(RTTI)
- 运行时类型识别RTTI
- RTTI 运行时类型识别
- RTTI 运行时类型识别
- Jquery选择器和.css,.addClass,.toggleClass
- linux端口重用
- Quartz2D的内存管理
- ubuntu通过xmange连接桌面
- WebServices CXF开发常见异常及解决方法
- js运行时类型识别的例子
- android尝鲜
- 调和级数之和1 + 1/2 + 1/3 + ...
- Linux下搭建Webdav(apache)
- 实现两个Spinner互相关联
- 装饰器模式
- Android TextView 超链接
- qt model删除选中的记录异常问题
- js 设置窗口为最大化