Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _ = require 'underscore'
- YobaEnum =
- PSHHH_PSSHHH: 0
- ALLO_ETO_YOBA: 1
- NYET: 2
- genSwitch = (EnumType) ->
- keys = _.keys EnumType
- names = _.invert EnumType
- (value, obj) ->
- if not ('default' of obj) and not (_.isEqual _.keys(obj), keys)
- throw new Error "hui sasi"
- else
- obj[names[value] ? 'default']()
- yobaSwitch = genSwitch YobaEnum
- x = YobaEnum.PSHHH_PSSHHH + 10
- yobaSwitch x,
- PSHHH_PSSHHH: => console.log "PSHHH"
- default: => console.log "DEFAULT"
- yobaSwitch x,
- PSHHH_PSSHHH: => console.log "PSHHH"
- NYET: => console.log "NYET"
Advertisement
Add Comment
Please, Sign In to add comment