How to declare class attributes easily?
class Autobot {
name = 'Optimus Prime';
fraction = 'Autobots';
}
const transformer = new Autobot();
// output: I am Optimus Prime and leader of the Autobots!
console.log(`I am ${transformer.name} and leader of the ${transformer.fraction}!`);
August 1st, 2022
In object-oriented programming, class attributes are often declared in the constructors. In JS, no constructor is needed.