布尔 Javascript 表达式在 Firebug Watch 窗口中返回 true,但在代码中返回 false?
我有一个带有名为“objFrame”的 IFrame 的网页。
在 Javascript 文件中,执行以下语句:
var useWindow = (typeof(window.objFrame) != "undefined" && typeof(window.objFrame.contentWindow) != "undefined");
运行代码时(通常或使用调试器单步调试),表达式
(typeof(window.objFrame) != "undefined" && typeof(window.objFrame.contentWindow) != "undefined")
为 true我将其粘贴到 Firebug 中的 Watch 窗口中,但 useWindow 得到的值为 false。
我使用的是 Firefox 3.0.6 和 Firebug 1.3.2。
我在这里缺少什么? 请告诉我这是我的一个简单的语法错误(?!?)
I have a web page with an IFrame named "objFrame".
In a Javascript file, the following statement is executed:
var useWindow = (typeof(window.objFrame) != "undefined" && typeof(window.objFrame.contentWindow) != "undefined");
When running the code (normally or stepping through it with the debugger), the expression
(typeof(window.objFrame) != "undefined" && typeof(window.objFrame.contentWindow) != "undefined")
is true when I paste it into the Watch window in Firebug, but useWindow gets the value false.
I am using Firefox 3.0.6 with Firebug 1.3.2.
What am I missing here? Please tell me that this is a simple syntactical error on my part(?!?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在 Firebug 中也看到过类似的情况,并且发现了两个问题/解决方法:
我正在使用 dojo,在调试器中看到一件事,而实际上是另一件事发生这样的代码模式(Firebug 中的 status = true 但实际上未定义):
dojo.byId("ajaxProgress").style.visibility = "隐藏";
var 状态=responseObject.status;
一旦我改变了这些线条的顺序,事情就开始符合现实。
I have seen something like this with Firebug as well, and have found two issues/workarounds:
I was using dojo and seeing one thing in the debugger and another thing actually happening with code pattern like this (status = true in Firebug but really undefined):
dojo.byId("ajaxProgress").style.visibility = "hidden";
var status = responseObject.status;
once I changed the order of those lines around, things started matching reality.
如果您编写日志语句、打印整个值以及每个组件的“typeof”结果,这可能会有所帮助。 还将这些内容输入 Firebug 控制台。
“window.objFrame”不是只存在于 IE DOM 中吗?
在 Firebug 论坛或 comp.lang.javascript 中提出这样的问题不是更有意义吗?
It might help if you write log statements, printing the entire value, and also the "typeof" result for each component. Also enter those into the Firebug console.
Isn't "window.objFrame" only in the IE DOM?
Wouldn't it make more sense to ask questions like this in either the Firebug forum or comp.lang.javascript?
我会一起去
如果可能的话
。 我认为这就是您想要检测的内容,但检查 typeof(null) 对我来说似乎有点不稳定。
(如果有充分的理由这行不通,请忽略我:))
I'd go with
if at all possible.
I think that's what you're trying to detect, but checking the typeof(null) seems a bit flaky to me.
(If there's a good reason this won't work, ignore me :))