Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I chain a method call to execute right after a recursive method finishes?
    text
    copied!<p>I need some help here, the scenario is the following: I have a recursive method for a Coffeescript class, and it executes itself exactly 4 times. I need to call another method from the same class right after this 4 iterations are completed, Let me illustrate a bit,</p> <pre><code>class Table constructor: (factor, zindex) -&gt; @factor = factor @zindex = zindex @dealt = false @player = new Player 'player' @house = new Player 'house' this.setDealing() setDealing: -&gt; self = this $('#deal').click -&gt; self.deal $('.one-card:last'), 0 if self.amount &gt; 0 &amp;&amp; not self.dealt #When the call to self.deal() above is done I need to call checkWinner() #How Can I do this? deal: (card, times) -&gt; $('#player-hand, #house-hand, #ask, #stop').show() @dealt = true self = this if (card.prev() || card.first()) &amp;&amp; times &lt; 4 cardValue = this.getCardValue card if @zindex % 2 == 0 then @house.push cardValue else @player.push cardValue top = cardPlace + @factor right = 550 - (@factor * 1.4) card.animate 'top': "+=#{top}" 'right': "+=#{right}" 350, -&gt; card = card.prev() #Recursive Call is done Here! self.deal card, times + 1 @factor += 10 @zindex += 1 checkWinner: -&gt; @player.isWinner() </code></pre> <p>As you can see, the recursive method is quite complex(or not..), and it takes some time to finish given that it does a number of animations(once per iteration). <strong>I have no idea</strong> how to call/chain another method to execute right after this recursive method is finally done. </p> <p>How can I accomplish this? Thanks in advance!</p> <p>Note: I placed one more line of code that was missing card = card.prev() which is needed for recursion to advance. Sorry about the confusion (if there was any)</p>
 

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