<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script type="text/javascript">
var class2type = {
'[object Boolean]' : 'boolean',
'[object Number]' : 'number',
'[object String]' : 'string',
'[object Function]' : 'function',
'[object Array]' : 'array',
'[object Date]' : 'date',
'[object RegExp]' : 'regexp',
'[object Object]' : 'object',
'[object Error]' : 'error'
};
function type( obj ) {
if ( obj == null ) {
return obj + "";
}
return typeof obj === "object" || typeof obj === "function" ?
class2type[ toString.call(obj) ] || "object" :
typeof obj;
};
function Foo() {}
function Bar() {}
Bar.prototype = new Foo();
var foo = new Foo();
var bar = new Bar();
console.log(type(''));
console.log(type(undefined));
console.log(type(null));
console.log(type(true));
console.log(type(false));
console.log(type(1));
console.log(type(0));
console.log(type(new String('foo')));
console.log(type(new Number(10)));
console.log(type({}));
console.log(type(new Date()));
console.log(type(new Error()));
console.log(type([1,2,3] ));
console.log(type(new Array(1, 2, 3)));
console.log(type(new Function("") ));
console.log(type(/abc/g));
console.log(type(new RegExp("meow")));
console.log(type(new Object()));
console.log(type(foo));
console.log(type(bar));
console.log(type(/abc/g));
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script type="text/javascript">
var class2type = {
'[object Boolean]' : 'boolean',
'[object Number]' : 'number',
'[object String]' : 'string',
'[object Function]' : 'function',
'[object Array]' : 'array',
'[object Date]' : 'date',
'[object RegExp]' : 'regexp',
'[object Object]' : 'object',
'[object Error]' : 'error'
};
function type( obj ) {
if ( obj == null ) {
return obj + "";
}
return typeof obj === "object" || typeof obj === "function" ?
class2type[ toString.call(obj) ] || "object" :
typeof obj;
};
console.log(typeof null);
console.log(class2type[ toString.call(null) ] );
console.log(type(null));
console.log(typeof undefined);
console.log(class2type[ toString.call(undefined) ] );
console.log(type(undefined));
</script>
</body>
</html>
object type.html:26
undefined type.html:27
null type.html:28
undefined type.html:29
undefined type.html:30
undefined

最新文章

  1. js转盘抽奖
  2. DailyRollingFileAppender的使用
  3. 判断密文加密类型hash-identifier
  4. DNX概述
  5. java学习笔记 (1) —— Strut2.3.24环境搭建
  6. WordPress插件制作教程(三): 添加菜单的方法
  7. 项目中Spring注入报错小结
  8. 6天通吃树结构—— 第三天 Treap树
  9. Smarty 注册变量
  10. python机器学习实战(一)
  11. 循环语句for,while,until,select
  12. Java经典编程题50道之十九
  13. mvvm,如何解析一个指令表达式?
  14. 【Python】 发邮件用 smtplib &amp; email
  15. window.open模拟表单POST提交
  16. Nginx location配置详解
  17. JqGrid把数据行插入指定位置的方法addRowData
  18. 如何将jar包添加到maven本地仓库
  19. Linux下不同颜色文件的类型
  20. EM算法求高斯混合模型參数预计——Python实现

热门文章

  1. Spring核心框架 - AOP的原理及源码解析
  2. Xcode 7.3.1的模拟器路径
  3. mysql 自定义排序顺序
  4. WordPress数据库中的表、字段、类型及说明
  5. oracle----删除数据
  6. 【弱省胡策】Round #7 Rectangle 解题报告
  7. C++的表驱动法
  8. 【HDOJ】1260 Tickets
  9. 【转】Mac QQ截图保存在哪里?
  10. linux cross toolsChain 交叉编译 ARM(转)