In JavaScript, you can create a class using the class
keyword, which allows you to define the properties and methods of the class.
Here's an example of a class that represents a person:
index.tsx194 chars11 lines
In the above example, the Person
class has a constructor method that takes in a name
and age
parameter and sets them as properties of the class instance. It also has a sayHello
method that logs a greeting including the name and age of the person.
To create an instance of the Person
class, you can use the new
keyword:
index.tsx112 chars3 lines
gistlibby LogSnag