DEV Community

TypeScript. Object-oriented programming (OOP) (opens in new tab)

Discussed on DEV

When we hear about OOP, what is the first thing that comes to mind? Classes! Basic structure Classes in TypeScript look pretty the same as in JavaScript only with specifying types. class Person { name: string; constructor(name: string) { this.name = name; } greet() { console.log(`Welcome, ${this.name}!`); } } const p1 = new Person("Mary"); p1.greet(); // Welcome, Mary! Access modifiers We can restrict or open access to specific properties or methods by using keywords: Private modifier The pri...

Read the original article
Sign in to keep reading the full article.

Keyboard Shortcuts

Navigation

Next / previous post
j/k
Open post
oorEnter
Preview post
v

Post Actions

Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Save / unsave
s

Recommendations

Add interest / feed
Enter
Not interested
x

Go to

Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Discover
gb
Search
/

General

Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help