Questions tagged [es6-symbol]

6 questions
3
votes
1 answer

Do not log symbols using util.inspect

I have this object which has some symbols properties on it: { foo: 'bar', [Symbol(raw.json.bytes)]: 13, [Symbol(raw.json.str)]: '{"foo":"bar"}' } now, I added those symbol properties myself, so maybe I can change how I add them using…
user11810894
1
vote
1 answer

What are name clashes and how do ES6 Symbols avoid name clashes between properties?

I am trying to understand Symbols in ES6 better, and I have read this answer: https://stackoverflow.com/a/22280202/5591717 They are now known as unique symbols and their only intended use is to avoid name clashes between properties. Does a name…
user10686399
1
vote
1 answer

Why doesn't assignment to Symbol.iterator throw an error?

In Chrome on Windows, I have this in the console: > Symbol.iterator < Symbol(Symbol.iterator) > Symbol.iterator = "Hello!"; < "Hello!" > Symbol.iterator; < Symbol(Symbol.iterator) So Symbol.iterator (thankfully) doesn't change, but why doesn't my…
Green Grasso Holm
  • 468
  • 1
  • 4
  • 18
1
vote
1 answer

Add Symbol property to array

I want to add some metadata to an array, like a tag, but not actual data. Say I have a symbol like: const s = Symbol('foo') Say I declare an array like so: const v = [1,2,3]; is there a good way to tag the array with the symbol? Obviously adding…
user1604294
1
vote
2 answers

Is it possible to leverage type safety with symbols?

Looking at this Typescript code : class A { } let a = new A(); let s: symbol = Symbol('sym'); a[s] = 2; a[s] = 'f'; a[s] = new Date(); //no errors We can see that same symboled property is referencing to a difference types . Question: Is it…
Royi Namir
  • 144,742
  • 138
  • 468
  • 792
0
votes
1 answer

JS Symbol Security -- Can a non-unique Symbol be created?

I'm writing an odd kind of webapp that is designed to communicate with other sites loaded into the browser. This is fairly trivial to do via MessageChannels. Now, these applications must access protected resources and must get authorization from the…
somebody0
  • 53
  • 6