What is the convention (standard) in TypeScript for class attributes?
In the angular 2 demo (The Heroes Tour from angular.io) all attributes are set to public :
export class Hero {
id: number;
name: string;
}
So they can be instanciated both ways :
var hero: Hero = new Hero();
hero.id = 0;
hero.name = "hero";
or
var hero2: Hero = {id : 0, name: "hero"};
Is there a Java style convention (like this) :
export class Hero {
private id: number;
private name: string;
setId(id: number): Hero {
this.id = id;
return this;
}
setName(name: string): Hero {
this.name = name;
return this;
}
getId(): number {
return this.id;
}
getName(): string {
return this.name;
}
}
Declaration (exemple) :
var hero: Hero = new Hero();
hero.setId(0).setName('hero');
var hero2: Hero = new Hero().setId(0).setName('hero');