#10417 closed feature (fixed)
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: | |
| Blocked by: | Blocking: |
Description (last modified by )
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 (28)
comment:1 Changed 10 years ago by
| Keywords: | 1.8-discuss added |
|---|
comment:2 Changed 10 years ago by
| Description: | modified (diff) |
|---|
comment:3 Changed 10 years ago by
comment:4 Changed 10 years ago by
| Component: | unfiled → core |
|---|
comment:5 Changed 10 years ago by
| Priority: | undecided → low |
|---|---|
| Status: | new → open |
comment:7 Changed 10 years ago by
| Description: | modified (diff) |
|---|
-1, There is no reason why this needs to depend on jQuery apart from bundling it.
comment:9 Changed 10 years ago by
| Description: | modified (diff) |
|---|
+1, It's small and we can use it internally, so yeah.
comment:10 Changed 10 years ago by
| Description: | modified (diff) |
|---|
+1, mostly fluff, but honestly, I'm personally sick of setTimeout( fn, 0). Let's do it.
comment:13 Changed 10 years ago by
+1
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 10 years ago by
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 10 years ago by
| Description: | modified (diff) |
|---|---|
| Owner: | set to gnarf |
| Status: | open → assigned |
comment:16 Changed 10 years ago by
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 9 years ago by
Even if it doesn't wrap any other method, just having it wrap setTimeout( fn , 0 ) is nice
comment:18 Changed 9 years ago by
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 9 years ago by
| Keywords: | 1.9-discuss added; 1.8-discuss removed |
|---|
comment:20 Changed 9 years ago by
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:26 Changed 9 years ago by
| Milestone: | None → 1.9 |
|---|
comment:27 Changed 9 years ago by
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Fix #10417. setTimeout w/o 2nd arg is jQuery.later! Close gh-1065.
Changeset: d41b983259042d3a07ae785c09f71c68d9ce7c3f
comment:28 Changed 9 years ago by
| Summary: | jQuery.later → Remove second arg from setTimeout calls (WAS jQuery.later) |
|---|

neat!