Classes
ΠΠ±ΡΡΠ²Π»Π΅Π½ΠΈΠ΅
class Typescript {
version: string
constructor(version: string) {
this.version = version
}
info(name: string) {
return `[${name}]: Typescript version is ${this.version}`
}
}
class Car {
readonly model: string
readonly numberOfWheels: number = 4
constructor(theModel: string) {
this.model = theModel
}
}
// ΠΠ°ΠΏΠΈΡΡ ΠΈΠ΄Π΅Π½ΡΠΈΡΠ½Π° ΠΏΡΠ΅Π΄ΡΠ΄ΡΡΠ΅ΠΉ
class Car {
readonly numberOfWheels: number = 4
constructor(readonly model: string) {}
}
ΠΠΎΠ΄ΠΈΡΠΈΠΊΠ°ΡΠΎΡΡ (protected, private, public)
class Animal {
protected voice: string = '' // protected β Π΄ΠΎΡΡΡΠΏΠ΅Π½ Π² ΠΊΠ»Π°ΡΡΠ΅ Animal ΠΈ Π²ΠΎ Π²ΡΠ΅Ρ
ΡΡΠ½ΠΊΡΠΈΡΡ
ΠΊΠ»Π°ΡΡΠΎΠ², ΠΊΠΎΡΠΎΡΡΠ΅ Π±ΡΠ΄ΡΡ Π½Π°ΡΠ»Π΅Π΄ΠΎΠ²Π°ΡΡΡΡ ΠΎΡ ΠΊΠ»Π°ΡΡΠ° Animal
public color: string = 'black' // public β ΠΌΠΎΠ΄ΠΈΡΠΈΠΊΠ°ΡΠΎΡ ΠΏΠΎ ΡΠΌΠΎΠ»ΡΠ°Π½ΠΈΡ
private go() {
console.log('Go')
}
}
ΠΠ±ΡΡΡΠ°ΠΊΡΡΠ΅ ΠΊΠ»Π°ΡΡΡ ΠΈ ΠΌΠ΅ΡΠΎΠ΄Ρ
ΠΠ½ΠΈ Π½ΠΈ Π²ΠΎ ΡΡΠΎ Π½Π΅ ΠΊΠΎΠΌΠΏΠΈΠ»ΠΈΡΡΡΡΡΡ, Π½ΠΎ Π½ΡΠΆΠ½Ρ Π½Π° ΡΡΠ°ΠΏΠ΅ ΡΠ°Π·ΡΠ°Π±ΠΎΡΠΊΠΈ
abstract class Component {
abstract render(): void
abstract info(): string
}
class AppComponent extends Component {
render(): void {
console.log('Component is renderer')
}
info(): string {
return 'some info'
}
}
Last updated