[JavaScript] Array filtern

// Alter, nach dem das Personenarray gefiltert werden soll
let filter_age = 60;

// Array mit Namen und Alter
let arr_persons = [ { name:"Horst", age:50 },
                    { name:"Udo", age:55 },
                    { name:"Heinz", age:60 },
                    { name:"Ede", age:65 } ];

// neues, gefiltertes Array
let arr_filtered = arr_persons.filter( function(p){
  return p.age >= filter_age;
} );

// Ausgabe des gefilterten Arrays
arr_filtered.forEach(function(p){
  console.log(p.name + ": " + p.age);
});

[JavaScript] Eigene Exceptions werfen

// https://www.w3schools.com/js/js_errors.asp
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error

try {
  throw new Error("Ein Error.");
  // throw new EvalError("Ein EvalError.");
  // throw new RangeError("Ein RangeError.");
  // throw new ReferenceError("Ein ReferenceError.");
  // throw new SyntaxError("Ein SytaxError.");
  // throw new TypeError("Ein TypeError.");
  // throw new URIError("Ein URIError.");
}
catch(e) {
  console.log(e);
}

[JavaScript] Klassenbasierte Vererbung

// https://javascript.info/class-inheritance
// https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Klassen

// ab ES6
class Car {
  constructor(name) {
    this.name = name;
  }

  drive() {
    console.log("Driving: " + this.name);
  }
}

class Audi extends Car {
  quadro() {
    console.log("Quadro: " + this.name);
  }
}

let a = new Audi("A4");
a.drive();
a.quadro();