对于IE,typeof window.close是不同的 [英] typeof window.close is different for IE

查看:85
本文介绍了对于IE,typeof window.close是不同的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我在键入 window.close 时看到奇怪的行为
显示 function close(){[native code]} < IE中的/ code>和Chrome中的 function(){[native code]} ,我认为两者都是函数。

Today I saw weird behavior when I typed window.close it showing function close() { [native code] } in IE and function () { [native code] } in chrome, I thought both are function.

但当我输入 typeof(window.close)时,它在IE8中显示'object' code> chrome中的'function'

But when I typed typeof(window.close) it showing 'object' in IE8 and 'function' in chrome.

为什么会出现这种不同的行为?
我可以使用哪些方法来检查JavaScript中变量的类型?
是否有其他功能显示此类行为?

Why this different behavior? What are the ways I can use to check type of a variable in JavaScript? Is there other functions which shows this type of behavior?

谢谢

推荐答案

这里了解你的情况应该有(即function)。

Look here for what you should have (ie "function").

这里的可读性较低但官方的ECMAScript参考。

And here for the less readable but official ECMAScript reference.

IE 8根本不遵守规范。这真的不是唯一的例子。

IE 8 simply doesn't follow the norm. That's really not the sole occurrence.

关于如何测试变量是否是IE8上的函数?问题,我无法测试我自己,但这可能有效:

Regarding the How to test if a variable is a function on IE8 ? question, I can't test it myself but this probably works :

var myvar = window.close;
var isfunc = Object.prototype.toString.call( myvar ) === '[object Function]';

这篇关于对于IE,typeof window.close是不同的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆