

Symbols in ECMAScript 6 - Raphael
http://www.2ality.com/2014/12/es6-symbols.html

======
Gorkys
Could anybody explain what problems this was designed to solve?

~~~
pilif
Same use (albeit with less nice syntax) as the ruby symbols.

Many frameworks based on ruby (like Rails) make heavy use of symbols.

They are handy as they are immutable, very cheaply comparable for equality and
(in ruby) very light on syntax and they can be made out of thin air whenever
you need one.

    
    
        some_array[:foo] = 'bar'
    

instead of

    
    
        FOO=0
        some_array[FOO] = 'bar';
    

(think how error prone it's going to be to add more keys like this. Forgotten
declarations, duplication declarations and so on).

You could use strings, but they are often heap-allocated (slow) and sometimes
(ruby) even mutable and thus way more expensive to compare for equality and
require some kind of hashing to put them as keys into hash tables. Symbols
don't. And never conflict.

~~~
k__
My idea of them was, they are like string-identifiers, but instead of creating
a new string for every string-literal the symbol-literal creates one global,
immutable instance.

------
nailer
So in practice, Symbols are likely to be used to replace UUIDs?

I'm not sure the color example reads particularly well, as the value of the
symbol would not actually be useful as a color (you could turn it into one,
but it wouldn't reflect the name of the constant).

------
dmak
What really? I haven't read through this yet, but my initial thought was the
annoying syntax in Rails. Sometimes you have 3 freaking ways to access
something which is dot syntax, brackets with a string, and brackets with a
symbol. I hope its better than I expect.

------
wtbob
What do these symbols add that's not possible with just using Objects as
symbols?

E.g. 'foo = {}; bar = {}; foo === bar' yields false.

