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.
In google chrome, if you want to log objects with the state they had at the time of logging, you need to log a clone object or just stringify it.
Will log
[3]because it logs a live object, while this will log[]:It is also a live object logging but it is a throwaway clone that was cloned at the point in time when
adidn’t have any items.This is not related to the possible logical errors in your code that @CallumRogers pointed out.