Node.JS v0.11.3 claims to have support for ECMAScript 6 symbols with the --harmony_symbols
flag (see here). The latest draft says
Properties are identified using key values. A key value is either an ECMAScript String value or a Symbol value.
I have tried the following example
var mySymbol = new Symbol('Test symbol');
console.log(mySymbol.name); // prints 'Test symbol', as expected
var a = {};
a[mySymbol] = 'Hello!';
but I get an error on the last line
TypeError: Conversion from symbol to string
How do symbols work? Is my example wrong, or does Node.JS actually not support symbols?
You should try without new
:
var mySymbol = Symbol('Test symbol');
console.log(mySymbol.name); // prints 'Test symbol', as expected
var a = {};
a[mySymbol] = 'Hello!';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With