xxxxxxxxxx
23
class Person {
constructor(name, hobby) {
this.name = name;
this.hobby = hobby;
}
vorstellen() {
console.log("Hallo, ich bin " + this.name +
" und mein Hobby ist " + this.hobby + ".");
}
}
const personA = new Person("Karin", "Programmieren");
const personB = new Person("Michael", "Lesen");
const personC = new Person("Rebecca", "Katze kraulen");
personA.vorstellen();
// -> Hallo, ich bin Karin und mein Hobby ist Programmieren.
personB.vorstellen();
// -> Hallo, ich bin Michael und mein Hobby ist Lesen.
personC.vorstellen();
// -> Hallo, ich bin Rebecca und mein Hobby ist Katze kraulen.