Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

coffeescript shorthand object notation #1808

Open
wants to merge 2 commits into from

6 participants

@paulmars

salary = 50
name = "Joe"
dept = "Accounting"
employee = {salary, name, dept}
output = "#{employee.name} works in #{employee.dept}"

added to the docs

@jashkenas
Owner

Nice idea, but the documentation tries to use "real-world" examples as much as possible, and not foo and bar...

@paulmars
@gabehollombe

+1 to get this merged. If you're still unhappy with the example provided by @showell in the comment above, let's try to get something that makes sense to @jashkenas. I'm happy to suggest another example if needed. I'd just love to see this added to the docs soon, since it's a great feature and I get sad when the docs aren't as comprehensive as they could be. This feels like something we can surely get into the docs without too much more effort.

@michaelficarra
Collaborator

@gabehollombe: There are many important, undocumented features. If it really does bother you, want to take it upon yourself to document them all and open a pull request? I'd love to finally see comprehensive documentation.

@paulmars

@jashkenas, would the example @showell described suffice? I'm happy to update.

@gabehollombe

@michaelficarra I would absolutely love to help out and start documenting the important features you think need documentation. Do you want to throw a list of targets for me up on the wiki, or in an email? Either way, please just share the areas you think need mentioning or improvement and I'll totally take a crack at it. =-)

@michaelficarra
Collaborator

@gabehollombe: Well, you could start with the various nuances of our whitespace sensitivity. The numerous issues mentioning undocumented features are also a good starting point.

@michaelficarra
Collaborator

@gabehollombe: As part of my kickstarter project, I'll be compiling a comprehensive list of all (intentional) coffeescript features. It probably won't be comprehensive on my first try, but it'll be a good place to look for features that may be lacking in documentation. I'll post a link when I'm done.

@gabehollombe
@paulmars

@showell I'd like to get this merged so I can make more improvements in the docs. Do you have merging abilities. If I make your recommended changes will this get merged?

@gabehollombe @michaelficarra Thanks for the support. Lets see if we can get this merged!

@showell

@paulmars Sorry, I don't have merge powers.

@paulmars

@jashkenas I believe the current code address all the thoughts brought up in this thread. Can you please merge?

documentation/index.html.erb
@@ -418,6 +418,11 @@ Expressions
about it (say, when using jQuery).
</p>
<%= code_for('objects_reserved') %>
+ <p>
+ CoffeeScript has a shortcut for creating objects when you want the object name
@michaelficarra Collaborator

I would say "key name" here. LGTM otherwise.

@satyr Collaborator
satyr added a note

Note that number/string literals also work.

@paulmars
paulmars added a note

@michaelficarra done.

@satyr I'm going to leave that for a future commit and pull request. I'd like to get this merged after 8 months of waiting rather than complicate the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@michaelficarra
Collaborator

@gabehollombe: @paulmars:

I forgot to post back here with some undocumented features. Here's some that I thought of this week:

  • existential operators (#1631)
  • not in, not of, not instanceof
  • let-expressions (do (x = y) ->)
  • standalone extends
  • anonymous classes
  • condition-less switch
  • seq operator (;)
  • destructuring everywhere assignment happens
  • shallow copy (postfix [..])
  • heregex interpolation
  • binary literals (0b01010101)
@jashkenas
Owner

I'd be glad to merge, but first -- let's change the example to be something a little more exciting than Joe in accounting. Use your imagination.

@gabehollombe

OK. Pick a theme: Zombies, Super Powers, or Famous Movie Characters. I'll have fun with it... =-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 29, 2012
  1. @paulmars
Commits on Jul 1, 2012
  1. @paulmars
This page is out of date. Refresh to see the latest.
View
5 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}"
View
5 documentation/index.html.erb
@@ -418,6 +418,11 @@ Expressions
about it (say, when using jQuery).
</p>
<%= code_for('objects_reserved') %>
+ <p>
+ CoffeeScript has a shortcut for creating objects when you want the key
+ to be set with a variable of the same name.
+ </p>
+ <%= code_for('objects_shorthand') %>
<p>
<span id="lexical_scope" class="bookmark"></span>
View
13 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;
Something went wrong with that request. Please try again.