Advertisement
Guest User

Untitled

a guest
Jun 20th, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. cart = (spec, my) ->
  2.   init = ->
  3.     if spec
  4.       my.sItemLabel = spec
  5.     else
  6.       my.sItemLabel = "Item"
  7.   iNumItemsOrdered = 0
  8.   iNumItemsLeft = 2
  9.   my = my or {}
  10.   init()
  11.   my.checkItemInventory = ->
  12.     iNumItemsLeft > 0
  13.  
  14.   that =
  15.     createCart: ->
  16.       console.log "CART. cart created."
  17.  
  18.     placeOrder: ->
  19.       console.log "CART. placed order for " + iNumItemsOrdered + " " + my.sItemLabel + "s."
  20.  
  21.     addItemToCart: ->
  22.       if my.checkItemInventory()
  23.         iNumItemsOrdered++
  24.         console.log "CART. " + my.sItemLabel + " added."
  25.         iNumItemsLeft--
  26.       else
  27.         console.log "CART. sorry " + my.sItemLabel + "s all gone!"
  28.  
  29.   that
  30.  
  31. sooperCart = (spec, my) ->
  32.   my = my or {}
  33.   that = cart(spec, my)
  34.   that.addAllItems = ->
  35.     console.log "CART. add ALL " + my.sItemLabel + "."
  36.     that.addItemToCart()  while my.checkItemInventory()
  37.  
  38.   that
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement