如何找到在运行时定义变量的位置? [英] How do I find where a variable is defined at runtime?

查看:220
本文介绍了如何找到在运行时定义变量的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

直到最近,我一直并排使用jQuery和YUI.有时,在回调(例如,YUI按钮)内部,$将被其他一些功能遮盖(单击以获取大版本):

I've been using jQuery and YUI side-by-side with no issues until recently. Occasionally, inside of a callback for, say, a YUI button, $ will be shadowed by some other function (click for big version):

在我的生命中,我不知道为什么会发生这种情况.是的,我知道我很安全,可以在任何地方使用jQuerywindow.$而不是仅仅使用$,但这只是一种解决方法,而不是实际的解决方法.

and for the life of me, I cannot figure out why this is happening. Yes, I know I could be safe and use jQuery or window.$ everywhere instead of just $, but that's just a workaround and not an actual fix.

在运行时,如何找到这个$冒名顶替者来自何处? -例如找到它的声明位置,以及为什么它在我的流血范围内.

At runtime, how can I find where this $ impostor is coming from? - e.g. find where it's declared, and why it's in my bleedin' scope.

事实证明,此行为很容易在Stack Overflow上重现(至少在Chrome和Firefox 4中如此),因为SO使用jQuery(再次单击以查看完整大小):

It turns out that this behavior is easily reproduced (at least in Chrome and Firefox 4) right here on Stack Overflow, since SO uses jQuery (again, click for full size):

我只能将$推断为

function () {
    return document.getElementById.apply(document, arguments)
}

必须来自控制台本身!

with再次触击.

此问题的铬错误: http://code.google. com/p/chromium/issues/detail?id = 70969

推荐答案

我敢保证IE中不会发生这种情况?这是我唯一能找到的提示:

I'm betting this doesn't happen in IE? This is the only hint I could find:

http://davidwalsh.name/dollar-functions

http://dam5s.tumblr.com/post/3079779011/bug-in-chromes-javascript-console

Chrome/Firefox/Safari中的某种错误.

Some sort of bug in Chrome/Firefox/Safari.

这篇关于如何找到在运行时定义变量的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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