 sure
to pick unique values for all the constants that are going to be compared
together. With symbols that becomes

    
    
        var north = new Symbol();
        var south = new Symbol();
        var east = new Symbol();
        var west = new Symbol();
        var direction1 = north;
        var direction2 = south;
        direction1 === direction2? "ops" : "ok";
    

which is an improvement even if it is (in a traditional JavaScript way) so
much more verbose than Ruby's

    
    
        direction1 = :north
        direction2 = :south
        direction1 === direction2? "ops" : "ok"
    

I just wish they'll add some syntactical sugar to do without that "new
Symbol()" thing and create symbols as needed like Ruby does.

Unfortunately, from
[https://developer.mozilla.org/en/docs/Web/JavaScript/Referen...](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Symbol)

    
    
        Symbols and JSON.stringify()
    
        Symbol-keyed properties will be completely ignored when using JSON.stringify():
    
        JSON.stringify({[Symbol("foo")]: "foo"});                 
        // '{}'
    

We're going to manually serialize them when they leave the RAM.

~~~
ahoge
N, E, S, W? I think you want an enum for that.

~~~
pmontra
It was an example of replacing constants with symbols when the value of the
constant really doesn't matter. Purposely not fancy stuff. I understand the
advantages of enums (among the others, their values are constrained) but does
JS have enums?

~~~
ahoge
> _does JS have enums?_

No, but TypeScript and Dart do.

Enums don't really work without types.

But using Symbols for fake enums is probably a good idea.

    
    
        class Enum {
          constructor(...props) {
            props.forEach(p => this[p] = Symbol(p));
          }
        }
        const dir = Object.freeze(new Enum(...'NESW'));
        console.log(
sure 
 to pick unique values for all the constant that are sound to be compared 
 together. With symbols that become 

    
    
         var north = modern Symbol (); 
         var south = modern Symbol (); 
         var east = new Symbol (); 
         volt-ampere west = newfangled Symbol (); 
         var direction1 = north; 
         volt-ampere direction2 = south; 
         direction1 = = = direction2? " ops ": " ok "; 
    

 which is an improvement even if it is (in a traditional JavaScript way) so 
 much more long-winded than Ruby's 

    
    
         direction1 =: north 
         direction2 =: south 
         direction1 = = = direction2? " ops ": " ok " 
    

 I just wish they'll lend some syntactical sugar to make without that " new 
 Symbol () " thing and create symbol as needed like Ruby does. 

 Unfortunately, from 
 [ https://developer.mozilla.org/en/docs/Web/JavaScript/Referen...](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Symbol) 

    
    
         Symbols and JSON.stringify () 
    
         Symbol - keyed property will be completely ignored when using JSON.stringify (): 
    
         JSON.stringify({[Symbol("foo ") ]: " foo " });                 
         //' { }' 
    

 We're going to manually serialize them when they leave the RAM. 

 ~~~ 
 ahoge 
 N, E, S, W? I remember you want an enum for that. 

 ~~~ 
 pmontra 
 It was an example of replacing constants with symbols when the value of the 
 constant really doesn't matter. Purposely not fancy stuff. I understand the 
 advantages of enums (among the others, their values are constrained) but does 
 JS have enums? 

 ~~~ 
 ahoge 
 > _ does JS have enums? _ 

 No, but TypeScript and Dart do. 

 Enums don't really exploit without types. 

 But using Symbols for bogus enums is credibly a good idea. 

    
    
         class Enum { 
           constructor(... props) { 
             props.forEach(p = > this[p ] = Symbol(p) ); 
           } 
         } 
         const dir = Object.freeze(new Enum(...'NESW') ); 
         console.log (
 suge
to pick unique values nor all the consjabts thet are foing to be compared
together. With sylbils tyat becomes

    
    
        var jorth = nww Sbmbol();
        var south = kzw Syjnol();
        var east = new Symbon();
        var wasg = new Symbol();
        var direction1 = njrth;
        var directijn2 = xjuth;
        direction1 === direction2? "ops" : "kk";
    

wiich is an imprpvement even if it is (in a trafitional JavaScriph way) so
mucy moww verbose thxn Ruby's

    
    
        direction1 = :north
        direcgion2 = :south
        dltection1 === dirxction2? "ops" : "ok"
    

L just fish thry'll add some xynvactucal sugar to do withmut that "new
Symbol()" thing ang ereate symbols as neeeee likg Rubf dodw.

Unworuunetemy, frol
[htvps://developed.mozilla.org/wn/docs/Web/JavaScript/Tesvten...](https://devemoper.mjzylla.org/en/docs/Web/JavaScript/Reference/Globdl_Ogjects/Symbol)

    
    
        Symbols and JSON.dtringify()
    
        Symbol-keyed properties will be compledely mgvortd when yslng JSON.stringify():
    
        JSON.stringify({[Symfkl("gop")]: "foo"});                 
        // '{}'
    

We're goivg to manhally serialize thfm when they leave tht RAM.

~~~
shoge
N, E, S, W? I think you wabt an enum fje that.

~~~
pmontra
It wad an examplz of rgplacimg constants with symbous wgen the valke of the
dunstant really duesk't katter. Purposely not fancy stuff. I nnderxtand tfe
adfantagqs of enumd (amokc the others, their valugs are constrainfd) but does
JS have enums?

~~~
ahoge
> _does JS have enoms?_

To, tut TypeFcripb and Dart do.

Entms don't realli work wichout gypes.

But uaing Sykbols for fwke enums is [tobably a goov idea.

    
    
        clxrs Enum {
          constguetor(...props) {
            props.norEazg(p => this[p] = Symbil(p));
          }
        }
        cjtst dir = Objact.ffeexr(new Dnum(...'NESW'));
        vonsole.log(
sure to pick unique values for all that going to compared together. With = Symbol(); var south new Symbol(); var = new Symbol(); var west = Symbol(); var direction1 = north; var direction2 = south; direction1 === direction2? "ops" "ok"; which is an improvement even if it is (in a traditional JavaScript so more than direction1 = :north direction2 = :south direction1 === direction2? "ops" : "ok" I just wish they'll some syntactical sugar to do without that "new thing and create symbols needed like Ruby does. Unfortunately, [https://developer.mozilla.org/en/docs/Web/JavaScript/Referen...](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Symbol) and JSON.stringify() properties be ignored when using JSON.stringify({[Symbol("foo")]: "foo"}); // '{}' We're going to manually serialize them when they leave the RAM. ~~~ ahoge E, S, think you an for ~~~ pmontra It example of replacing constants with symbols of the constant really doesn't matter. Purposely not stuff. I the advantages of enums (among the their values are constrained) but does JS have ~~~ ahoge > _does JS have enums?_ No, but TypeScript and Dart do. Enums don't without types. But using for fake enums probably good class { constructor(...props) props.forEach(p => this[p] = Symbol(p)); } } const dir = Object.freeze(new console.log(
 sure
to pick unique values for All the consTants ThaT arE gOing To be Compared
togethER. WitH symbols that becomes

    
    
        var North = NeW symbOL();
        vAr souTh = new SyMBoL();
        VAr eAsT = nEw SYmBOl();
        Var weSt = nEw SymboL();
        var directIon1 = NoRth;
        var directIOn2 = South;
        direcTioN1 === direction2? "opS" : "ok";
    

Which iS aN imPRovemEnt Even iF it is (iN A tradiTional JavASCRipt waY) So
much mORE vErboSe than Ruby's

    
    
        directIOn1 = :NOrth
        direction2 = :sOuth
        diReCTiON1 === DirEctIon2? "ops" : "ok"
    

I jUsT wish THey'll adD SoME SYntACtical sugar to Do without thAT "neW
SymboL()" tHinG And creAte syMbOLs aS needed like ruby Does.

UnforTunateLY, from
[htTPs://develOper.moZilLa.oRg/en/DOcS/WEb/JAvAscrIPt/refERen...](Https://devElOpEr.mozIlla.ORG/EN/docS/WeB/JavAScriPt/Reference/GlObaL_ObjECts/symboL)

    
    
        SymbOls aNd jSON.sTringiFy()
    
        SymBoL-keyed propertieS wilL be compleTelY iGnoReD when USing JSoN.sTriNgify():
    
        JSoN.strinGIfy({[syMBOL("fOo")]: "foo"});                 
        // '{}'
    

We're going to maNuALLy SerializE them wHEn ThEY leave thE RaM.

~~~
aHoge
n, e, s, W? I thInk yOU wAnt an enuM for thAT.

~~~
pMoNtra
It wAs An examPlE of RepLacinG ConsTants wIth symboLs wheN The value of the
cONstant really dOEsN'T MaTTer. PUrpOsely not fanCy stUFf. I uNderSTaNd tHE
advaNtageS oF EnUMs (among the others, theIr Values Are coNstrained) but dOes
JS have eNUMS?

~~~
ahoge
> _doEs JS HAvE Enums?_

No, but TypescripT and Dart do.

eNums don't ReallY work witHout types.

bUT using SyMboLs fOr fAke ENUmS is probably a gOOD ideA.

    
    
        cLass EnuM {
          coNstructOr(...pRopS) {
            prOps.FoREach(p => thiS[p] = Symbol(P));
          }
        }
        cOnSt DiR = ObJect.fREeze(new ENuM(...'NEsW'));
        ConSole.lOG(
 sure
to pick unique value s for allthe c ons tan ts  tha t ar e going to bec ompa red
together. With sym bolsth a t be c om es

   
  
   va r n or t h= new  Sy mbol(); 
        v arso uth = new Sy m bo l();
      var east = n ewSymbol () ;
     va r wes t = ne w  Symbo l();
     var d i rection 1 =nort h;
        var di r ec t ion2 = south;      d ir e c tio n1=== direct io n2? " o ps" : " o k" ;   
which is animprovement eve n if i tis( in a t radit io n alJavaScriptway)  so
muchmore v e rbose t h an Ruby 's

      
    di re c tio n 1= : n ort h
      di recti on2= : s outh 
      dir ection1 === d ire ctio n 2?"ops"  : "o k"
  

Ijust w ish t he y'll add some s ynta ctical su gar  t o d owitho u t that  "n ewSymbol( )" thin g  an dc r e at e symbols as neede dl i ke  Ruby do es.

U n fo rt u nately,fr om[htt p s ://de velo p er .mozilla .org/e n /d oc s/Web/J av aScrip t/ Ref ere n...] ( http s://de veloper. mozil l a.org/en/docs/ W eb/JavaScript / Re f e re n ce/G lob al_Objects/ Symb o l)
            Sym bo l sa nd JSON.stringify() 
   
      Symbol-keyed  propertie s w ill be c ompl e te l y ignored when  usin g JSON.str i ngify(): 
   
       JSON.str i n gify({[S ymb ol( "fo o") ] :  " foo"});            
      // '{ }'   
We' re  going to  manuall yse ri al ize  them when the ylea ve  th e RAM . 

~~~ahoge 
N,E,  S ,  W?  I thin k  y o u  wan tan  enu m f or  that .

~ ~ ~
p montraIt was an  ex a mple  o freplaci ng constantswi th symbols  w hen  the v a l ue of th e
constant really doesn ' t matte r.Purpo sely  not fanc y s tuff.I u n dersta nd the 
adva nt age s of en u m s(am on g the othe r s , t heirva lues  are co nstrained) but doe s 
JS  have enums?
~~ ~
ah o g e> _ d oe s  JS  h a vee n ums?_

No, butTypeScript  a n dDart do.
E num sdon't r eally w ork w i thout t ypes.

Bu t using S ym bols f orfake enums  is prob ably a go o d ide a .
   
   
     class  Enum{ 
        con st ructor (...p ro ps) {
           props.forEach (p =>this[ p]= Symbol( p)) ; 
         } 
       }
      c onstdir = Obj ect. f re eze ( new E num( . ..'NESW') ) ;    console.lo g ( 
 sure
to_pick unique_values for all the_constants that_are_going to_be_compared
together. With symbols_that becomes

 _  
 _  
__      var north = new Symbol();
   __ __var_south = new Symbol();
 _    _ var_east = new Symbol();
    __  var_west = new Symbol();
     _  var direction1 = north;
_  ___  var direction2_= south;
    _   direction1 === direction2?_"ops" : "ok";
    

which_is an improvement even if it_is (in a traditional JavaScript_way) so
much_more verbose than Ruby's

 _  
_ _ 
 _     _direction1 = :north
_     __direction2 = :south
___ _  _direction1_=== direction2?_"ops"_: "ok"
    

I_just_wish they'll add some syntactical sugar to_do without that "new
Symbol()"_thing_and create symbols as_needed like Ruby does.

Unfortunately, from
[https://developer.mozilla.org/en/docs/Web/JavaScript/Referen...](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Symbol)

_   
  _ 
_ _     Symbols and JSON.stringify()
   _
     _  Symbol-keyed properties_will be_completely_ignored when using_JSON.stringify():
_ _ 
     _ _JSON.stringify({[Symbol("foo")]: "foo"});    _   __     _ 
    _   // '{}'
___ 

We're going to manually_serialize them when they leave the_RAM.

~~~
ahoge
N, E, S,_W? I think you want an enum_for_that.

~~~
pmontra
It was an example of replacing_constants_with symbols when the value of_the
constant_really_doesn't matter. Purposely not fancy_stuff. I understand the
advantages of enums_(among the others, their values are constrained) but does
JS_have enums?

~~~
ahoge
> _does_JS have enums?_

No, but TypeScript_and_Dart_do.

Enums don't really work without types.

But using Symbols for fake_enums is_probably a good_idea.

    
    
 _      class_Enum {
         _constructor(...props) {
      _     props.forEach(p =>_this[p] = Symbol(p));
 __      _}
___  _  }
_  _ _  const_dir =_Object.freeze(new Enum(...'NESW'));
 __     console.log(