Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>using <code>setTimeout(func(),0)</code> in order to execute synchronously</p> </blockquote> <p>No. Either use <code>func()</code> for a synchronous execution, or <code>setTimeout(func, 0)</code> to queue the execution (which makes it asynchronous).</p> <blockquote> <p>Is <code>setTimeout(func[…],0)</code> the "most elegant" way to put this action onto the execution queue for rendered webpage objects? In other words, is there a "more elegant" way to block execution (i.e. do these things sequentially)?</p> </blockquote> <p>Yes, this is the standard method. However, this does <em>not</em> block execution, and has nothing to do with sequencing. If the execution is synchronous, just execute it, if not you will have to deal with the callbacks and queuing a new task does <em>not</em> help.</p> <blockquote> <p>Is anyone aware of how much this callback business looks like goto() in other languages? Meaning, this nesting of callbacks feels very awkward and inelegant to me. Is there a Javascript language construct either being developed or already developed that will reduce this crazy business?</p> </blockquote> <p>No, I'm not aware of other languages, but afaik <code>goto</code> is a synchronous, control-flow-structuring statement as does not deal with asynchronous actions.</p> <p>But no, there are no JavaScript language constructs ("syntactic sugar") that help us around the <a href="http://en.wikipedia.org/wiki/Continuation-passing_style" rel="nofollow noreferrer">continuation-passing style</a> with its callback hell.</p> <blockquote> <p>Is there a function/object I could use to apply these actions sequentially, to cut down on the callback hell going on here? In other words, what would an object look like if the object/function were able to synchronously execute each action as it was individually iterated through it (i.e. passed to it)?</p> <p>My goal here is a tight, elegant, attractive, homegrown Javascript object/function -- that I can call in a for() loop or equivalent -- to apply these operations on each action in sequence.</p> </blockquote> <p>Again you want "sequencially" instead of "synchronous" :-) Yes, there are [handcoded/homegrown] solutions which make dealing with callbacks easier. As <a href="https://stackoverflow.com/a/4289363/1048572">those callback organisation libraries</a> you mentioned do not satisfy you, I'd recommend to look into the very elegant and attractive <a href="http://wiki.commonjs.org/wiki/Promises" rel="nofollow noreferrer"><code>Promise</code> Api</a> and its Deferred objects (see <a href="http://en.wikipedia.org/wiki/Futures_and_promises" rel="nofollow noreferrer">futures and promises</a> for the concept).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload