Chinaunix

标题: 部分浏览器对typeof方法的错误实现 [打印本页]

作者: so_brave    时间: 2011-03-18 17:14
标题: 部分浏览器对typeof方法的错误实现
转:Snandy

部分浏览器对typeof方法的错误实现



1,IE6/7/8中typeof运算符对BOM对象如window,document,location,history等错误的返回“object”,标准浏览器都返回“function”。
  1. 1 alert(typeof window.alert);  

  2. 2 alert(typeof document.write);  

  3. 3 alert(typeof document.getElementById);  

  4. 4 alert(typeof document.getElementsByTagName);  

  5. 5 alert(typeof location.reload);  

  6. 6 alert(typeof history.go);
复制代码
2,Safari/Chrome对正则对象错误的返回function
  1. 1 var bb = new RegExp('bb');  

  2. 2 alert(typeof /aa/);// --> function  

  3. 3 alert(typeof bb);// --> function
复制代码





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2