Destructuring arguments in Coffeescript
A traditional function might look like this:
createPost = (title, content, options = {}) ->
    category = options.category
    headline = options.headlineUsing CoffeeScript's destructuring assignment makes this nicer:
createPost = (title, content, options = {}) ->
    {category, headline} = optionsAnd finally, if you don't need the explicit options variable, you can even do:
createPost = (title, content, {category, headline} = {}) ->Written by Kamil Tusznio
Related protips
1 Response
 
Note: The default value of "{}" is important to prevent type errors when no "options" argument is provided.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
 #Coffeescript 
Authors
Related Tags
#coffeescript
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#
 
 
 
