static class typescript code example
Example 1: typescript static class equivalent
//Example of Typescript static class equivalent
export abstract class Tools {
public static truncate(str, length) {
var ending = '...';
if (str.length > length) {
return str.substring(0, length - ending.length) + ending;
} else {
return str;
}
};
}
Example 2: classes in typescript
class Info {
private name: string ;
constructor(n:string){
this.name = n ;
};
describe(){
console.log(`Your name is ${this.name}`);
}
}
const a = new Info('joyous');
a.describe();