Discussion:
Defining a Symbol object to be use as a property object
L2L 2L
2014-10-10 05:06:26 UTC
Permalink
I've played around with Symbol. And from my understanding, they are use to define unique properties and variable --I'm still not fully knowledgeable on them, only what I read. So if you would like to give your summary of them, please feel free.--.

My proposal is to be able to define an symbol object:

var obj = new Symbol("symbol obj");

Why?

To be able defined properties for objects with keys of symbol, as so:

var obj = {};

obj.propObj = new Symbol("propObj");

obj.propObj.prop = Symbol("prop");

This is doable via all constructor wrapper objects for all primitive data types.

It'll be a nice addition to this primitive type to have the same capability.

This is my proposal.

E-S4L
N-S4L
J-S4L
Salvador de la Puente González
2014-10-10 07:43:03 UTC
Permalink
Ups.
---------- Forwarded message ----------
From: "Salvador de la Puente Gonz?lez" <salva at unoyunodiez.com>
Date: 10 Oct 2014 08:04
Subject: Re: Defining a Symbol object to be use as a property object
To: "L2L 2L" <emanuelallen at hotmail.com>
I don't know why do you want to do so but if it is because you want to
hide a complete structure from the outside world then remember symbols can
var myPrivate = Symbol();
var obj = {};
obj[myPrivate] = {};
Hope it solves your use case.
Post by L2L 2L
I've played around with Symbol. And from my understanding, they are use
to define unique properties and variable --I'm still not fully
knowledgeable on them, only what I read. So if you would like to give your
summary of them, please feel free.--.
Post by L2L 2L
var obj = new Symbol("symbol obj");
Why?
var obj = {};
obj.propObj = new Symbol("propObj");
obj.propObj.prop = Symbol("prop");
This is doable via all constructor wrapper objects for all primitive data types.
It'll be a nice addition to this primitive type to have the same capability.
This is my proposal.
E-S4L
N-S4L
J-S4L
_______________________________________________
es-discuss mailing list
es-discuss at mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20141010/69e48c4d/attachment.html>
L2L 2L
2014-10-10 08:43:19 UTC
Permalink
I declined from my proposal as it seem to be a way...--I haven't figure it out yet, or still don't fully understand the nature of Symbol-- my apology.

E-S4L
N-S4L
J-S4L
Post by L2L 2L
I've played around with Symbol. And from my understanding, they are use to define unique properties and variable --I'm still not fully knowledgeable on them, only what I read. So if you would like to give your summary of them, please feel free.--.
var obj = new Symbol("symbol obj");
Why?
var obj = {};
obj.propObj = new Symbol("propObj");
obj.propObj.prop = Symbol("prop");
This is doable via all constructor wrapper objects for all primitive data types.
It'll be a nice addition to this primitive type to have the same capability.
This is my proposal.
E-S4L
N-S4L
J-S4L
_______________________________________________
es-discuss mailing list
es-discuss at mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
Andrea Giammarchi
2014-10-10 09:01:46 UTC
Permalink
Symbols are basically a way to create "private" keys otherwise unaccessible
( except for `Objeect.getOwnPropertySymbols` that AFAIK will exposes them
anyway ).

Symbols are also sometimes used to define special "magic" behaviors

A sort of polyfill to play with Symbols in ES5 capable engines is here:
https://gist.github.com/WebReflection/5238782

Bear in mind that might be outdated or not fully spec compliant.

Regards
Post by L2L 2L
I declined from my proposal as it seem to be a way...--I haven't figure it
out yet, or still don't fully understand the nature of Symbol-- my apology.
E-S4L
N-S4L
J-S4L
Post by L2L 2L
I've played around with Symbol. And from my understanding, they are use
to define unique properties and variable --I'm still not fully
knowledgeable on them, only what I read. So if you would like to give your
summary of them, please feel free.--.
Post by L2L 2L
var obj = new Symbol("symbol obj");
Why?
var obj = {};
obj.propObj = new Symbol("propObj");
obj.propObj.prop = Symbol("prop");
This is doable via all constructor wrapper objects for all primitive
data types.
Post by L2L 2L
It'll be a nice addition to this primitive type to have the same
capability.
Post by L2L 2L
This is my proposal.
E-S4L
N-S4L
J-S4L
_______________________________________________
es-discuss mailing list
es-discuss at mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
es-discuss at mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20141010/94261d87/attachment.html>
Loading...