Side navigation
#3695 closed enhancement (duplicate)
Opened December 06, 2008 03:26PM UTC
Closed January 31, 2009 04:45PM UTC
Don't convert $(undefined) to $(document), use arguments.length instead.
Reported by: | dw | Owned by: | flesler |
---|---|---|---|
Priority: | minor | Milestone: | 1.3 |
Component: | core | Version: | 1.2.6 |
Keywords: | Cc: | dw | |
Blocked by: | Blocking: |
Description
Hey there,
The shortcut syntax for $(document)
, i.e. $()
, seems to be the cause of a rather subtle pain for people like me trying to fabricate a lot of code quickly.
In the past week I've had 2 problems with my code base where Firefox would suddenly show a blank document, Firebug would show nothing in the DOM, and yet the page loading indicator would continue to animate. I had originally thought some strange interaction with the Flash player was causing the problem. When I first encountered it I eventually reverted my change, amounting to losing over an hour's work, not including the time taken during the failed debugging session.
Today I just had the same problem, but this time only a small amount of code had changed and so manually auditing everything was possible. It turns out the problem was due to something like this:
$(this._dilePanel).text('')
Where this._dilePanel
was actually supposed to be spelled this._idlePanel
. The resulting expression evaluates to undefined
, which appears to trigger jQuery's $()
shortcut. Following the .text()
call, you can guess what happens next.
In total I think I've lost between 4-5 hours because of this "shortcut", and as such I think it should be considered for removal (or simply made benign!) in some future release.
Debugging this problem was exacerbated in my case because the call was happening in response to a network-originated event, and so had no immediate obvious correlation to something I was doing in the web browser.
I can't help but wonder how many others have been bitten by this. :) Thoughts?
Perhaps there is a trivial fix which involves testing for arguments.length == 0
rather than the first function parameter being undefined
?
Thanks,
David
PS: jQuery ''rocks!
Attachments (0)
Change History (3)
Changed December 07, 2008 07:09PM UTC by comment:1
cc: | → dw |
---|---|
milestone: | → 1.3 |
owner: | → flesler |
status: | new → assigned |
type: | bug → enhancement |
Changed December 07, 2008 07:11PM UTC by comment:2
summary: | Interface problem: $(typo_resulting_in_undefined).text('') = hard to diagnose blanked document. → Don't convert $(undefined) to $(document), use arguments.length instead. |
---|
I like the arguments.length approach.
Will look into this asap, for 1.3.