DEV Community

Sujith V S
Sujith V S

Posted on

2 1

New generation syntax for JavaScript classes | ES6 / Babel

A class mainly have properties and methods.
Properties are like 'Variables attached to classes'.
Methods are like 'functions attached to classes'.

Let's take a look at a class which has the new gen syntax,

class Human {
    gender = 'male';
    printGender = () => {
        console.log(this.gender);
    }
}

class Person extends Human {
    name = "Max";
    printMyName = () => {
        console.log(this.name);
    }
}
Enter fullscreen mode Exit fullscreen mode

Here we exclude the constructor function and directly assign the value to a variable inside the class.
And then we use arrow functions syntax to create method inside the class.

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay