Bug Tracker


Ticket #10417 (closed feature: fixed)

Opened 3 years ago

Last modified 15 months ago

Remove second arg from setTimeout calls (WAS jQuery.later)

Reported by: gnarf Owned by: gnarf
Priority: low Milestone: 1.9
Component: core Version: git
Keywords: 1.9-discuss Cc:
Blocking: Blocked by:

Description (last modified by gnarf) (diff)

We are starting to use more and more setTimeout( fn, 0 ); calls around our code base. I think now that there is also a setImmediate and there is also the postMessage that we should probably try to take advantage of these.

I would like to propose a jQuery.later( fn ) that wraps the "best" possible function here.

Change History

comment:1 Changed 3 years ago by gnarf

  • Keywords 1.8-discuss added

comment:2 Changed 3 years ago by gnarf

  • Description modified (diff)

comment:3 Changed 3 years ago by rwaldron


comment:4 Changed 3 years ago by rwaldron

  • Component changed from unfiled to core

comment:5 Changed 3 years ago by dmethvin

  • Priority changed from undecided to low
  • Status changed from new to open

comment:6 Changed 2 years ago by sindresorhus

#10936 is a duplicate of this ticket.

comment:7 Changed 2 years ago by jzaefferer

  • Description modified (diff)

-1, There is no reason why this needs to depend on jQuery apart from bundling it.

comment:8 Changed 2 years ago by jaubourg

+1, not only does it make sense, it should also save some size.

comment:9 Changed 2 years ago by dmethvin

  • Description modified (diff)

+1, It's small and we can use it internally, so yeah.

comment:10 Changed 2 years ago by mikesherov

  • Description modified (diff)

+1, mostly fluff, but honestly, I'm personally sick of setTimeout( fn, 0). Let's do it.

comment:11 Changed 2 years ago by rwaldron

  • Description modified (diff)

+1, Seems highly useful

comment:12 Changed 2 years ago by timmywil

  • Description modified (diff)

-1, I don't think it's worth it

comment:13 Changed 2 years ago by hkdobrev@…


It should save size and it would really prevent jQuery users from bad usage of setTimeout. For example many developers still do things like:

setTimeout("a lot of javascript in a string", ...)

comment:14 Changed 2 years ago by gibson042

I like the standardization and size neutrality (jquery.js has 5 instances of setTimeout( fn, 0..1 ), making this cost at most 12 bytes minified). But how about calling it jQuery.soon?

comment:15 Changed 2 years ago by gnarf

  • Owner set to gnarf
  • Status changed from open to assigned
  • Description modified (diff)

comment:16 Changed 2 years ago by timmywil

I'll elaborate. I don't think this will give us the benefit we're looking for. In terms of performance, adding the function call will likely negate the benefit of using postMessage. The best performance always has the smallest stack. Besides, we're talking ops in the millions if comparing postMessage to setTimeout. As for setImmediate, it is not currently implemented in any browser except IE and will probably never become part of the spec. IE10 will implement it as msSetImmediate. I definitely don't think we should make use of that yet.

It is my understanding that the overall direction for browser vendors is to optimize for setTimeout(fn, 0) rather than add another function. We could very well be forcing the jQuery API to go in a direction we will regret later. I'm not saying never, but I suggest we table it.

comment:17 Changed 23 months ago by gnarf

Even if it doesn't wrap any other method, just having it wrap setTimeout( fn , 0 ) is nice

comment:18 Changed 22 months ago by dmethvin

We haven't done this yet in 1.8, but I'm also not seeing any place where it is going to save us anything in the current code. Thoughts? Should we push to 1.9 and discuss then?

comment:19 Changed 19 months ago by gibson042

  • Keywords 1.9-discuss added; 1.8-discuss removed

comment:20 Changed 19 months ago by dmethvin

Thoughts about the benefits? The setTimeout implementation adds a relatively large delay but is not a lot of code. I'm on the fence about it now.

comment:21 Changed 19 months ago by gibson042

I'm neutral on this too, but +1 if it reduces size.

comment:22 Changed 19 months ago by mikesherov

+1, I'm with @gibson042 on this. If it's smaller, sure.

comment:23 Changed 19 months ago by rwaldron

+1, But we need to bikeshed on the naming

comment:24 Changed 18 months ago by gibson042

+1, if it reduces size

comment:25 Changed 18 months ago by anonymous


comment:26 Changed 18 months ago by mikesherov

  • Milestone changed from None to 1.9

comment:27 Changed 17 months ago by Oleg

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

Fix #10417. setTimeout w/o 2nd arg is jQuery.later! Close gh-1065.

Changeset: d41b983259042d3a07ae785c09f71c68d9ce7c3f

comment:28 Changed 15 months ago by dmethvin

  • Summary changed from jQuery.later to Remove second arg from setTimeout calls (WAS jQuery.later)

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


Add a comment

Modify Ticket

as closed

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

Note: See TracTickets for help on using tickets.