If you're going to do the @@
sigil, why not just place it directly on the name? The getting and setting could be determined from function signature.
class Foo
@@random: -> Math.random()
@@name: -> Db.query 'name'
@@name: (newName) -> Db.update 'name', newName
I don't particularly like how close it is to @
while being very different in action.
What about a named attribute like property
? You could also go with a shorter prop
but I think the full version fits more with CoffeeScript ethos.
class Foo
property random: -> Math.random()
property name: -> Db.query 'name'
property name: (newName) -> Db.update 'name', newName
This might be easier to implement since it's basically a function with an object argument.
You could also go down a similar path to some other languages and add a symbol after the slot name:
class Foo
random^: -> Math.random()
name^: -> Db.query 'name'
name=: (newName) -> Db.update 'name', newName
^
being completly original whereas =
has precdent.
I also think hacking the computed property syntax looks ok but would still lead to reserved usage albeit inside of computed property expressions only.
class Foo
[get random]: -> Math.random()
[get name]: -> Db.query 'name'
[set name]: (newName) -> Db.update 'name', newName
For that matter, I don't mind the {get foo}:
idea mentioned above in a similar vein with less conflicts.