fnstuff

0.0.1alpha • Public • Published

Allows the declaration of argument structure.

-   X     : any type. X is a placeholder for the argument name (not used)
-  {X}    : object type
-  "X"    : string type
-  X->    : function type
-     ?   : arg can be 'undefined'
- [    ]  : arg is optional (can be left out)

e.g.:

 myfunc = Fn ' "name" [{options}?] callback-> ', (name, options, callback) ->

The name can be missing from the argument syntax, so the above is the same as...

 myfunc = Fn ' "" [{}?] -> ', (foo, options, cb) ->

Missing arguments are always passed in as 'undefined'.

 myfunc = Fn ' foo bar ', (foo, bar) -> console.log "#{foo} #{bar}"
 myfunc('hello')
 > 'hello undefined'

Extra arguments throw an error.

 myfunc = Fn ' foo bar ', (foo, bar) -> console.log "#{foo} #{bar}"
 myfunc('hello', 'coffee', 'donut') # throws error

Package Sidebar

Install

npm i fnstuff

Weekly Downloads

1

Version

0.0.1alpha

License

none

Last publish

Collaborators

  • jaekwon