1)为什么在IE 8中 typeof(window [“alert”])是“对象”而不是功能?
2)如何在“window.alert”上调用apply方法?我的意思是我要做的就是:
function exec(method, param)
{
//because of typeof(window["alert"]) == "object" the actual if looks like typeof(window[method]) == 'function' || method == 'alert'
if(typeof(window[method]) == 'function')
{
window[method].apply(window, [param]);
}
}
exec("alert","hello");
答案 0 :(得分:1)
尝试此代码(typeof而不是typeOf())
function exec(method, param)
{
if(typeof window[method] == 'function')
{
window[method].apply(window, [param]);
}
}
exec("alert","hello");
答案 1 :(得分:1)
typeof window["alert"]
在9以下的Internet Explorer版本中返回“object”,但在Firefox中它返回“function”。我想这是一个众所周知的问题。下面是一篇提到它的文章:
答案 2 :(得分:0)
typeof(window [“alert”])返回“function”
您已撰写 typeOf 。这工作
function exec(method, param)
{
//because of typeof(window["alert"]) == "object" the actual if looks like typeof(window[method]) == 'function' || method == 'alert'
if(typeof(window[method]) == 'function')
{
window[method].apply(window, [param]);
}
}
exec("alert","hello");