To call a property on an instance of a class in TypeScript, you first need to create a new instance of the class using the new
keyword.
Assuming you have a class Person
with a property name
, the following code creates a new instance of Person
and sets the name
property to "John"
:
index.ts124 chars10 lines
To call the name
property on the john
instance, simply use dot notation:
index.ts42 chars2 lines
This will output the value of the name
property, which is "John"
.
gistlibby LogSnag