日期:2014-05-17 浏览次数:22220 次
<script type="text/javascript">
window.onload = function() {
document.getElementById("info").innerHTML = "typeof undefined == " + (typeof undefined) + //"undefined"
"<br/>typeof null === " + (typeof null) + //"object"
"<br/>typeof true === " + (typeof true) + //"boolean"
"<br/>typeof 1 === " + (typeof 1) + //"number"
"<br/> typeof \"hello\" === " + (typeof "hello") + //"string"
"<br/> typeof new Date() === " + (typeof new Date()) + //"object"
"<br/> typeof (new Date()).getDate === " + (typeof (new Date()).getDate) + //"function"
"<br/> typeof document.getElementById === " + (typeof document.getElementById) + //"function"
"<br/> typeof document === " + (typeof document); //"object"
}
</script>
<div id="info"></div>
function A(){
}
var a=new A();
alert(type of a);//object
<script type="text/javascript">
function isFunction( fn ) {
return !!fn && //不为空,存在
!fn.nodeName && //不是节点对象
fn.constructor != String && //不是字符串类型
fn.constructor != RegExp && //不是正则表达式
fn.constructor != Array && //不是数组
/function/i.test( fn + "" ); //toString()中包含"function"
}
alert(isFunction(document.getElementById)); //true
</script>