This one's going to be short.
I was reading some stuff on Ruby and was perplexed by this stuff that looks like
:name
so I looked into it and it turns out that it's a sort of object that doesn't really represent anything other than a sort of unique abstract value. And any two symbols with the same name after the colon there are considered the same. I think this is quite interesting because it means you can use these as variables for objects that have a property that can take one of a small number of values, without having to rigidly define exactly what those values are.
Obviously you can get sort-of similar activity just by using a string
"name"
since any two strings with the same text will be equal, so I'm not entirely sure why you'd use symbols, but I thought I'd think of some way of doing this in Javascript. I figure you can have a special function, like just $("name") that returns a globally defined symbol object, maybe like
function $(name){
return window[name] || (window[name] = { "id2name": name, "inspect": "$"+name, ... });
which works exactly as you want it too, but is really just ugly and nowhere near as elegant as the Ruby solution. Shame you can't just do
$name
or something.