Bug Tracker

Modify

Ticket #3695 (closed enhancement: duplicate)

Opened 5 years ago

Last modified 5 years ago

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
Blocking: Blocked by:

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!

Change History

comment:1 Changed 5 years ago by flesler

  • Cc dw added
  • Owner set to flesler
  • Type changed from bug to enhancement
  • Status changed from new to assigned
  • Milestone set to 1.3

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

comment:2 Changed 5 years ago by flesler

  • 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.

comment:3 Changed 5 years ago by dmethvin

  • Status changed from assigned to closed
  • Resolution set to duplicate

This is a duplicate of #1807 .

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.