Ticket #3695 (closed enhancement: duplicate)
Don't convert $(undefined) to $(document), use arguments.length instead.
|Reported by:||dw||Owned by:||flesler|
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:
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?
PS: jQuery rocks!
- Cc dw added
- Owner set to flesler
- Type changed from bug to enhancement
- Status changed from new to assigned
- Milestone set to 1.3
- Summary changed from Interface problem: $(typo_resulting_in_undefined).text('') = hard to diagnose blanked document. to Don't convert $(undefined) to $(document), use arguments.length instead.