Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggestion] New syntax for dynamic key in hash #3630

Closed
MatrixFr opened this issue Sep 10, 2014 · 2 comments
Closed

[Suggestion] New syntax for dynamic key in hash #3630

MatrixFr opened this issue Sep 10, 2014 · 2 comments

Comments

@MatrixFr
Copy link

Hi,

I discover a problem in Javascript this morning: if i want a hash with dynamic key.

In PHP for exemple, no problem:

$test = [
   $foo => 42,
   Klass::myConst => 44
];

What I wish do in coffee :

class myClass
  @MY_CONST1 = 42
  @MY_CONST2 = 422
  @MY_ASSOC_CONST = {
     @MY_CONST1: 'baz'
     @MY_CONST2: 'test'
  }

What I have to do for this time:

class myClass
  @MY_CONST = 42
  @MY_ASSOC_CONST = {}
  @MY_ASSOC_CONST[@MY_CONST] = 'baz'

So maybe we can choose a symbol to say "it's a dynamic key in this hash, compile that!" like simply:

class myClass
  @MY_CONST = 42
  @MY_ASSOC_CONST = {
     'foo': 'bar'
     @MY_CONST:: 'baz'
  }

when use "::" separator in hash, it will compile it in 2 times :

this.MY_ASSOC_CONST = {
  'foo': 'bar'
};
this.MY_ASSOC_CONST[this.MY_CONST] = 'baz';

What do you think about that?

@MatrixFr MatrixFr changed the title Suggestion [Suggestion] New syntax for dynamic key in hash Sep 10, 2014
@vendethiel
Copy link
Collaborator

Duplicate of #3597.

@MatrixFr
Copy link
Author

What they said in other topic it's to use the "manual solution", what I used now.
But I propose new syntaxic sugar to simplify our life about this problem. ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants