所以这适用于 Firefox 和歌剧,但不适用于 chrome 或 IE。 window.onload=function(){ IMS=new Object(); IMS.putLog=console.log; IMS.putLog('IMS Initialized...'); IMS.putLog('Loading...'); loadData(userName, passWord); IMS.putLog('Loaded...'); };因非法调用而失败不知道为什么?有什么建议吗? 最佳答案 原因是当你调用 IMS.putLog 时,函数的 this 变量是 IMS ; console.log 实现可能指望 this 是 console 。这是一个解决方法:IMS.putLog = console.log.bind(console);这将确保调用日志函数时 this 是 console。不幸的是,这在 IE bind 在 PhantomJS 中不起作用,如果这很重要的话。关于javascript - 分配给新变量时,console.log 崩溃?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22081618/
10-10 23:12