您的位置:首页 > 其它

console.log 报错 uncaught typeerror illegal invocation

2012-06-18 12:22 525 查看
因为ie不支持console.log的原因 封装了一层 代码如下

function debug(){

window.console && console.log.apply(null , arguments);
}

FF下正常 chrome下把错uncaught typeerror illegal invocation

原因是console.log的运行上下文要求是console不能是其它任何别的object

console.info.call(this,"stuff")
TypeError:Illegal invocation
console.info.call(console,"stuff")
stuff

修改代码为
window.console && console.log.apply(console , arguments);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: