I have a section of Javascript/Coffeescript that seems to be executing out of order.
console.log list
console.log list[card_number]
if list[card_number]
console.log "MATCHES"
new_card = list[card_number]
else
console.log "NO MATCHES"
new_card = create_new_card(card_number)
create_new_card: (card_number) ->
new_card =
card_number: card_number
list[new_card.card_number] = new_card
return new_card
Every time I run this, the first console.log
shows a list of cards that includes the new_card, Even if the card hasn't been created yet. Then it ALWAYS hits the else
, no matter how many times it is run.
If I attempt to run list[<card_number>]
in the Javascript console after this code runs, I receive the proper object, but each time the code runs on it's own, the same event happens.