cart = (spec, my) -> init = -> if spec my.sItemLabel = spec else my.sItemLabel = "Item" iNumItemsOrdered = 0 iNumItemsLeft = 2 my = my or {} init() my.checkItemInventory = -> iNumItemsLeft > 0 that = createCart: -> console.log "CART. cart created." placeOrder: -> console.log "CART. placed order for " + iNumItemsOrdered + " " + my.sItemLabel + "s." addItemToCart: -> if my.checkItemInventory() iNumItemsOrdered++ console.log "CART. " + my.sItemLabel + " added." iNumItemsLeft-- else console.log "CART. sorry " + my.sItemLabel + "s all gone!" that sooperCart = (spec, my) -> my = my or {} that = cart(spec, my) that.addAllItems = -> console.log "CART. add ALL " + my.sItemLabel + "." that.addItemToCart() while my.checkItemInventory() that