Typescript ile Class ismini dinamik olarak almak
typescript, programming, beginner, class, constructor


getClassName Yaklasimi
getClassName YaklasimiHer seferinde tekrardan isim dǒndururlur
class Base {
getClassName() {
return this.constructor.name;
}
}
class Derived extends Base {}
const derivedInstance = new Derived();
console.log(derivedInstance.getClassName()); // "Derived" çıktısını verir
readonly className Yaklasimi
readonly className YaklasimiTek seferlik atama yapilir ve memoryde tutulur
class Base {
readonly className = this.constructor.name;
}
class Derived extends Base {}
const baseInstance = new Base();
console.log(baseInstance.className); // "Base" çıktısını verir
const derivedInstance = new Derived();
console.log(derivedInstance.className); // "Derived" çıktısını verirPreviousTypescript full-stack projeleri icin proje dizin yapisi ve tsconfig dosyasi nasiNextTypeScript ile decorator tanimlayarak methodlari ve siniflari loglamak
Last updated
Was this helpful?