Automatically giving symbols descriptions

# Axel Rauschmayer (9 years ago)

I love how ES6 automatically gives anonymous function definitions names (via the variables they are assigned to etc.). Wouldn’t the same make sense for symbols?

Hypothetical example:

const foo = Symbol();
console.log(Symbol('foo').toString()); // Symbol(foo)
# Jordan Harband (9 years ago)

One difference is that functions are syntax - I don't believe var foo = new Function(); will have a "name" property inferred. Because Symbol is an identifier that has to be looked up on the global object, might there be difficulty inferring what the name should be?

Hopefully someone with more knowledge on the subject will confirm or correct my belief and my question :-)

# Mark S. Miller (9 years ago)

Yup. Consider

const foo = x();

where x happens to have the original value of Symbol.

Or

const foo = Symbol()

where Symbol is not bound to the original value of Symbol.

# Matthew Robb (9 years ago)

I'd still love to have symbol syntax using the @ident form or something. (I'm aware that it would likely conflict with the current decorators proposal).

# Claude Pache (9 years ago)

Le 8 janv. 2016 à 16:28, Matthew Robb <matthewwrobb at gmail.com> a écrit :

I'd still love to have symbol syntax using the @ident form or something. (I'm aware that it would likely conflict with the current decorators proposal).

What would be a concrete syntax? The following one seems nice:

{
    symbol @foo;  // lexical declaration of symbol; roughly equivalent to: const __foo__ = Symbol('foo');
    a. at foo = b; // roughly equivalent to: a[__foo__] = b; where __foo__ is the symbol @foo declared above.
}

However, it is just a little sugar for something perfectly doable in ES2015. Personally, I prefer to keep the syntax complexity budget for truly new things like private state: wycats/javascript-private-state, wycats/javascript-private-state

# Alexander Jones (9 years ago)

I'm not sure about going down the path of having sigils, i.e. the @ - there's not really any reason I can see for this IMO. I do agree with others that having to repeat yourself when defining a symbol is quite lame.

Perhaps if we opened up my earlier proposal for shorthand let- and and const-function (and class), it would make sense to define let-symbol and const-symbol, too. This would offer IMO a neat rounding off of these ES2015 features.

e.g. all of these pairs of statements would be equivalent:

const function doTheThing() {};
const doTheThing = function doTheThing() {};

const class MyClass {};
const MyClass = class MyClass {};

const symbol mySym;
const mySym = Symbol("mySym");

Just another idea.

Alex

# /#!/JoePea (9 years ago)

On Fri, Jan 8, 2016 at 9:45 AM, Alexander Jones <alex at weej.com> wrote:

const symbol mySym; const mySym = Symbol("mySym");

​Nice, I like that one.​