javascript:console.log在这种情况下不工作? [英] javascript: console.log not working in this context?

查看:74
本文介绍了javascript:console.log在这种情况下不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(function( $ ){ $.fn.openlayers = function( mapElementId, options ) {
        alert(console.log);
        console.log(options);
        ...
    }
});

我试图扩展javascript库中的功能,但很多我的惊喜,当我开始时意识到 console.log 没有记录任何内容。我知道代码正在执行,因为 alert()正确射击。但是,来自alert函数的返回响应似乎是function(){},这是正确的吗?或者实际上是console.log和空函数?

Im trying to extend functionality in a javascript library, but much to my suprise, when i got started i realized that nothing was being logged by console.log.. I know that the code is being executed due to the alert() firing properly. However the returned response from the alert function seems to be "function(){}", is that correct? or is in fact console.log and empty function?

所以这里有什么线索,以及为什么console.log不能正常工作?

So any clues on what's going on here, and why console.log isn't working?

我想我可能找到了罪魁祸首。我正在使用OpenLayers javascript文件,我可以看到他们的库设置

I think i might have found the culprit. Im working with a OpenLayers javascript file, and i can see that their library sets

OpenLayers.Console={log:function(){},...

然而,这是大写的控制台,但也许这不是区别?我也必须在OpenLayers范围内,我无法真正看到我。所以我仍然有点困惑。但它可以解释为什么我看到一个空函数

However, this is uppercase Console, but maybe that doesn't make a difference? I also have to be in the OpenLayers scope, which i can't really see that i am. So i'm still a little baffled. But it would explain why i'm seeing an empty function

这是我从输入console得到的输出加载发生此错误的应用程序后的chrome调试窗口。

This is the output i get from typing "console" in the debug window of chrome after loading the application where this error occurs.

assert: function (){}
count: function (){}
debug: function (){}
dir: function (){}
dirxml: function (){}
error: function (){}
group: function (){}
groupEnd: function (){}
info: function (){}
log: function (){}
profile: function (){}
profileEnd: function (){}
time: function (){}
timeEnd: function (){}
trace: function (){}
warn: function (){}
__proto__: Object

所以看起来似乎那个东西,可能是openlayers javascript覆盖了原生控制台。

So it would seem that something, possibly the openlayers javascript is overriding the native console.

推荐答案

在之前添加以下行 OpenLayer脚本告诉它不要覆盖控制台功能。

Add the following line before OpenLayer script to tell it not to override the console functions.

<script type="text/javascript">
    console.firebug=true;
</script>

这篇关于javascript:console.log在这种情况下不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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