Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jun 20th, 2012  |  syntax: CoffeeScript  |  size: 0.89 KB  |  views: 26  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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