-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathListing_3-59.js
27 lines (27 loc) · 889 Bytes
/
Listing_3-59.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function Person(firstName, lastName) {
// Objekteigenschaften
this.firstName = firstName;
this.lastName = lastName;
}
// Statische Eigenschaft
Person.MAX_WEIGHT = 2000;
// Statische Methode
Person.createDummyPerson = function() {
return new Person('Max', 'Mustermann');
};
// Objektmethoden
Person.prototype.getFirstName = function() {
return this.firstName;
};
Person.prototype.getLastName = function() {
return this.lastName;
};
// Ausgabe: 2000
console.log(Person.MAX_WEIGHT);
// Ausgabe: Person {firstName: "Max", lastName: "Mustermann"}
console.log(Person.createDummyPerson());
// Fehlermeldung, da getFirstName() keine statische Methode ist:
// console.log(Person.getFirstName());
console.log(new Person('Moritz', 'Mustermann').getFirstName()); // Moritz
// Fehlermeldung, da createDummyPerson() keine Objektmethode ist:
// console.log(new Person().createDummyPerson());