Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
September 9, 2022 06:54 am GMT

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);    }}

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.


Original Link: https://dev.to/sujithvsuresh/new-generation-syntax-for-javascript-classes-es6-babel-3dp5

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To