Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Methoden zum Hinzufügen und Entfernen von Artikeln
- // gloabales Array mit allen Artikeln
- var artikelSet = new Set();
- function neuerArtikel(name, preis, beschreibung, sonderpreis){
- let artikel = new Artikel(name);
- artikel.preis = preis;
- artikel.beschreibung = beschreibung;
- artikel.sonderpreis = sonderpreis;
- artikelSet.add(artikel);
- }
- function deleteArtikel(artikel){
- artikelSet.delete(artikel);
- }
- function neuerSchuh(name, groesse, preis){
- let schuh = new Schuhe(name, groesse);
- schuh.preis = preis;
- artikelSet.add(schuh);
- }
- function deleteSchuh(schuh){
- artikelSet.delete(schuh);
- }
- function listArticles(){
- return artikelSet;
- }
- let Schuhe = function(name, schuhgroesse) {
- Artikel.call(this, name);
- let _schuhgroesse = schuhgroesse;
- let _schuhmarke = undefined;
- let _preis;
- Object.defineProperty(this, 'schuhgroesse', {
- get: function() { return _schuhgroesse;},
- configurable: false
- });
- Object.defineProperty(this, 'schuhmarke', {
- get: function() { return _schuhmarke;},
- set: function(schuhmarke) {_schuhmarke = schuhmarke;}
- });
- Object.defineProperty(this, 'preis', {
- get: function() { return (this.sonderpreis == undefined) ? _preis : this.sonderpreis;},
- set: function(preis) {
- if (preis >= 5) {_preis = preis;}
- }
- });
- }
- Schuhe.prototype = new Artikel;
- Schuhe.prototype.toString = function() {
- // "superclass" toString response for current object + new toString additions
- return Object.getPrototypeOf(Object.getPrototypeOf(this)).toString.call(this) + "<br>Schuhgröße: " + this.schuhgroesse + "<br>Schuhmarke: " + this.schuhmarke;
- }
- Schuhe.prototype.constructor = Schuhe;
- delete Schuhe.prototype.beschreibung;
- delete Schuhe.prototype.id;
- delete Schuhe.prototype.name;
- delete Schuhe.prototype.preis;
- delete Schuhe.prototype.sonderpreis;
- let Artikel = function(name) {
- // id für den Artikel generieren
- Artikel.lastId = (Artikel.lastId) ? Artikel.lastId+1 : 1;
- let _id = Artikel.lastId;
- // Name festlegen
- let _name = name;
- if (_name == "" || name == undefined) {
- _name = "Artikel_" + _id;
- }
- // Beschreibung festlegen
- let _beschreibung;
- // Preis
- let _preis = 0;
- // Der Sonderpreis ersetzt den regulären Preis
- let _sonderpreis = undefined;
- // Objekt Definitionen
- Object.defineProperty(this, 'id', {
- get: function() { return _id;},
- configurable: false
- });
- Object.defineProperty(this, 'name', {
- get: function() { return _name;},
- set: function(name) {
- if (name != "" && name != undefined) {_name = name;}
- }
- });
- Object.defineProperty(this, 'beschreibung', {
- get: function() { return _beschreibung;},
- set: function(beschreibung) {_beschreibung = beschreibung;}
- });
- Object.defineProperty(this, 'preis', {
- get: function() { return (_sonderpreis == undefined) ? _preis : _sonderpreis;},
- set: function(preis) {
- if (preis >= 0) {_preis = preis;}
- },
- configurable: true
- });
- Object.defineProperty(this, 'sonderpreis', {
- get: function() { return _sonderpreis;},
- set: function(sonderpreis) {
- if (sonderpreis >= 0) {_sonderpreis = sonderpreis;}
- if (sonderpreis == undefined) {_sonderpreis = sonderpreis;}
- }
- });
- }
- /**
- * diese Methode vergleicht die Preise
- */
- Artikel.prototype.isCheaperThan = function(artikel2) {
- return (this.preis < artikel2.preis);
- }
- /**
- * für die Ausgabe
- */
- Artikel.prototype.toString = function() {
- return "Id: " + this.id + "<br>Name: " + this.name + "<br>Beschreibung: " + this.beschreibung + "<br>Preis: " + this.preis;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement