0

I came accross a following piece of code and i got confused and unable to understand the syntax used. I would need help to break some hightlighted

let HT = HT || {}; //What is this syntax and what does it do ?

//Are we adding an Hexagon object to the object HT ?
HT.Hexagon = function(id, x, y) {

}

//Are we adding an object named  Orientation to the object Hexagon ?
HT.Hexagon.Orientation = {
    Normal: 0,
    Rotated: 1
};

//Are we adding an object named Static to the object Hexagon ?
HT.Hexagon.Static = {
    HEIGHT:91.14378277661477, 
    WIDTH:91.14378277661477,
    SIDE:50.0,
    ORIENTATION:HT.Hexagon.Orientation.Normal,
    DRAWSTATS: false
};

How can one convert this piece of code to the modern ES6 classes ?

Kenzo
  • 1,767
  • 8
  • 30
  • 53

1 Answers1

1

The first line code is using the or operator. The operator checks first the expression on its left side - in this case the HT (it's probably an existing object.) If the expression is true e.g. holds a value like an object a number or a string etc, the expression will be assigned to the variable.

If HT does not hold any value which means it is false. Than it assign's the expression on its righte side - in this case an empty object.

The answer for your other three question is yes.

And it's not old JS at all.