class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}}
let greeter = new Greeter("world");Try
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();
class Person{
private name: string;
public constructor(name: string)
{
this.name = name
}
public getName():string{
return this.name;
}
}
var p = new Person("Jane Doe");
console.log(p.getName());
/*this example is more proper than the previous, though the previous example is syntax-wise correct*/
class Person{
public name: string;
public constructor(name: string)
{
this.name = name
}
}
var p = new Person("Jane Doe");
console.log(p.name);
/*for typescript, you need to not only specify the type in the normall places(e.g. constructor instead of name is name:string), but you also need to specify what the methods are above the constructor*/
/*not necessarily the recommended format for getting name, but at least this is gramatically correct*/
class Greeter { greeting: string;
constructor(message: string) { this.greeting = message; }
greet() { return "Hello, " + this.greeting; }}
let greeter = new Greeter("world");Try
class Person{
private name: string;
public constructor(name: string)
{
this.name = name
}
public getName():string{
return this.name;
}
}
var p = new Person("Jane Doe");
console.log(p.getName());
/*this example is more proper than the previous, though the previous example is syntax-wise correct*/
class Person{
public name: string;
public constructor(name: string)
{
this.name = name
}
}
var p = new Person("Jane Doe");
console.log(p.name);
/*for typescript, you need to not only specify the type in the normall places(e.g. constructor instead of name is name:string), but you also need to specify what the methods are above the constructor*/
/*not necessarily the recommended format for getting name, but at least this is gramatically correct*/