Shorthand expression of JS objects in CoffeeScript
CoffeeScript has a wonderful little shorthand expression for Javascript objects. Say you have a javascript object that looks like this:
var name = "Paul Jensen";
var age = 27;
var occupation = "Software developer";
var person = {
name: name,
age: age,
occupation: occupation
};
We could express the person object in CoffeeScript like this:
name = "Paul Jensen"
age = 27
occupation = "Software developer"
person = {name,age,occupation}
CoffeeScript is smart enough to recognise the variable names, and use them as the Object's keys.
Written by Paul Jensen
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Coffeescript
Authors
iam4x
94.17K
ericdfields
63.02K
Related Tags
#coffeescript
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#