몇 가지 도움이 필요합니다. 시나리오는 다음과 같습니다. Coffeescript 클래스에 대해 재귀 적 메서드가 있으며 정확히 4 번 실행됩니다. 나는이 4 반복을 완료 한 후 바로 같은 클래스에서 다른 메소드를 호출 할 필요가 (.. 여부)재귀 메서드 완료 직후에 실행할 메서드 호출을 체인화하는 방법은 무엇입니까?
class Table
constructor: (factor, zindex) ->
@factor = factor
@zindex = zindex
@dealt = false
@player = new Player 'player'
@house = new Player 'house'
this.setDealing()
setDealing: ->
self = this
$('#deal').click ->
self.deal $('.one-card:last'), 0 if self.amount > 0 && 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) ->
$('#player-hand, #house-hand, #ask, #stop').show()
@dealt = true
self = this
if (card.prev() || card.first()) && times < 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, ->
card = card.prev()
#Recursive Call is done Here!
self.deal card, times + 1
@factor += 10
@zindex += 1
checkWinner: ->
@player.isWinner()
하면, 재귀 방법은 매우 복잡 볼 수 있듯이, 내가 조금 설명하자 및 여러 애니메이션 (반복마다 한 번)을 수행하면 완료하는 데 시간이 걸립니다. 이 재귀 메서드가 마친 직후에 다른 메서드를 호출하여 체인을 호출하는 방법을 알지 못합니다.
어떻게하면됩니까? 미리 감사드립니다.
참고 : 재귀를 진행하는 데 필요한 card = card.prev()가 누락 된 코드를 한 줄 더 추가했습니다. 혼란에 대해 죄송합니다 (있는 경우)
재귀를 추적하는 것이 까다로울 것이라고 생각합니다. 특히 모든 반복마다 애니메이션이 수행되는 경우가 그렇습니다.어쨌든, isRunning 변수를 어디에 두어야할지 내 문제는 알지 못합니다. – jlstr
mmmm 사실 그것은 까다 롭습니다. 그러나 문제를 해결할 것입니다.이 경우 isRunning 변수는 생성자에서 설정 될 수 있습니다. –