Skip to content

Instantly share code, notes, and snippets.

@bitsmuggler
Last active August 29, 2015 14:03
Show Gist options
  • Save bitsmuggler/bcc00ba3eb3bd8b1928c to your computer and use it in GitHub Desktop.
Save bitsmuggler/bcc00ba3eb3bd8b1928c to your computer and use it in GitHub Desktop.
Übung in OOP Workshop @ejs14
/** @constructor */
function Person(name, age, geschlecht) {
this.name = name;
this.age = age;
this.geschlecht = geschlecht;
}
/** Methode */
Person.prototype.getName = function() {
return this.name;
};
Person.prototype.getAge = function() {
return this.age;
};
Person.prototype.getGeschlecht = function() {
return this.geschlecht;
};
function Customer(name, age, geschlecht, gekauftesObjekt) {
this.gekauftesObjekt = gekauftesObjekt;
Person.call(this, name, age, geschlecht);
}
Customer.prototype = new Person();
Customer.prototype.getName = function() {
return "Kunde " + Person.prototype.getName.call(this);
};
Customer.prototype.shop = function() {
return this.gekauftesObjekt;
};
var person1 = new Person('Person 1', 20, 'M');
var person2 = new Person('Person 2', 80, 'W');
var person3 = new Person('Person 3', 30, 'M');
var persons = [person1, person2, person3];
var customer = new Customer('Person 4', 70, 'W', 'ipod');
persons.push(customer);
for(var i in persons) {
logPerson(persons[i]);
if(persons[i] instanceof Customer) {
logCustomer(persons[i]);
}
}
function logPerson(person){
console.log(person.getName() + ' ' + person.getAge() + ' ' + person.getGeschlecht());
}
function logCustomer(customer) {
console.log('kauft ein ' + customer.shop());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment