Bug Tracker

Opened 15 years ago

Closed 14 years ago

#3695 closed enhancement (duplicate)

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:


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:


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!

Change History (3)

comment:1 Changed 14 years ago by flesler

Cc: dw added
Milestone: 1.3
Owner: set to flesler
Status: newassigned
Type: bugenhancement

I like the arguments.length approach. Will look into this asap, for 1.3.

comment:2 Changed 14 years ago by flesler

Summary: Interface problem: $(typo_resulting_in_undefined).text('') = hard to diagnose blanked document.Don't convert $(undefined) to $(document), use arguments.length instead.

comment:3 Changed 14 years ago by dmethvin

Resolution: duplicate
Status: assignedclosed

This is a duplicate of #1807 .

Note: See TracTickets for help on using tickets.