213 shaares
1 résultat
taggé
convert
ENFIN !!!
BON SANG JE LA CHERCHAIS CETTE FEATURE ! <3
class Person {
public name: string = "default"
public address: string = "default"
public age: number = 0;
public constructor(init?:Partial<Person>) {
Object.assign(this, init);
}
public printSomething() {
return 'toto is ' + this.name;
}
}
let persons = [
new Person(),
new Person({}),
new Person({name:"John"}),
new Person({address:"Earth"}),
new Person({age:20, address:"Earth", name:"John"})
];
console.log(new Person({name:"John"}).printSomething());
// => toto is John
console.log(new Person({name:"John"}).constructor.name);
// => person