Skip to content

Instantly share code, notes, and snippets.

@ryasmi
Created October 3, 2015 16:42
Show Gist options
  • Save ryasmi/6333e0be42b59d7295da to your computer and use it in GitHub Desktop.
Save ryasmi/6333e0be42b59d7295da to your computer and use it in GitHub Desktop.
abstract = (argTypes..., retType) -> (value) ->
val = (args...) ->
args.forEach((arg, index) ->
if arg.constructor isnt argTypes[index]
throw new Error('Invalid arg')
)
ret = value(args...)
if ret.constructor isnt retType
throw new Error('Invalid ret')
ret
val.type = arguments.callee
val
move = abstract(String)
#ride = move () -> 10
ride = move () -> 'ride'
Vehicle = abstract(Object)
Bicycle = Vehicle () ->
move: ride
#alert(Bicycle.type is Vehicle)
#alert(ride('sfsdf'))
alert(ride())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment