diff --git a/documentation/coffee/objects_shorthand.coffee b/documentation/coffee/objects_shorthand.coffee new file mode 100644 index 0000000000..ce5d709ab1 --- /dev/null +++ b/documentation/coffee/objects_shorthand.coffee @@ -0,0 +1,5 @@ +salary = 50 +name = "Joe" +dept = "Accounting" +employee = {salary, name, dept} +output = "#{employee.name} works in #{employee.dept}" diff --git a/documentation/index.html.erb b/documentation/index.html.erb index 522ad10849..e31a205a8d 100644 --- a/documentation/index.html.erb +++ b/documentation/index.html.erb @@ -418,6 +418,11 @@ Expressions about it (say, when using jQuery).

<%= code_for('objects_reserved') %> +

+ CoffeeScript has a shortcut for creating objects when you want the key + to be set with a variable of the same name. +

+ <%= code_for('objects_shorthand') %>

diff --git a/documentation/js/objects_shorthand.js b/documentation/js/objects_shorthand.js new file mode 100644 index 0000000000..cf2681d5fe --- /dev/null +++ b/documentation/js/objects_shorthand.js @@ -0,0 +1,13 @@ +var dept, employee, name, output, salary; + +salary = 50; +name = "Joe"; +dept = "Accounting"; + +employee = { + salary: salary, + name: name, + dept: dept +}; + +output = "" + employee.name + " works in " + employee.dept;