简体   繁体   English

IE的typeof window.close有所不同

[英]typeof window.close is different for IE

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. 今天,当我键入window.close时看到了奇怪的行为,在IE中显示了function close() { [native code] } function () { [native code] } ,在chrome中显示了function () { [native code] } ,我认为两者都是函数。

But when I typed typeof(window.close) it showing 'object' in IE8 and 'function' in chrome. 但是当我键入typeof(window.close)它在IE8中显示了'object' ,而在chrome中显示了'function'

Why this different behavior? 为什么会有这种不同的行为? What are the ways I can use to check type of a variable in JavaScript? 我可以使用哪些方式检查JavaScript中变量的类型? Is there other functions which shows this type of behavior? 还有其他功能可以显示这种行为吗?

Thanks 谢谢

Look here for what you should have (ie "function" ). 在这里查找您应该拥有的东西(即"function" )。

And here for the less readable but official ECMAScript reference. 此处提供了不太可读但官方的ECMAScript参考。

IE 8 simply doesn't follow the norm. IE 8完全没有遵循规范。 That's really not the sole occurrence. 这确实不是唯一的情况。

Regarding the How to test if a variable is a function on IE8 ? 关于如何测试变量是否是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]';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM