直到最近,我一直并排使用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):
在我的生命中,我不知道为什么会发生这种情况.是的,我知道我很安全,可以在任何地方使用jQuery或window.$而不是仅仅使用$,但这只是一种解决方法,而不是实际的解决方法.
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再次触击.
此问题的铬错误: 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:
davidwalsh.name/dollar-functions
dam5s.tumblr/post/3079779011/bug-in-chromes-javascript-console
Chrome/Firefox/Safari中的某种错误.
Some sort of bug in Chrome/Firefox/Safari.
更多推荐
如何找到在运行时定义变量的位置?
发布评论