works only with ecmaScript2015
class Man {
private _name: string = "DefaultName";
get name(): string {
return this._name
}
set name(value: string) {
console.log('been here');
value ? this._name = value : console.log('error');
}
constructor(name?: string) {
(name) && (this._name = name);
}
}
const man = new Man();
man.name = "Stanley";
console.log(man.name);