Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Czlowiek {
- constructor(imie, nazwisko){
- if(typeof(imie) !== "string")
- throw "imie != string";
- if(typeof(nazwisko) !== "string")
- throw "nazwisko != string";
- this._imie = imie;
- this._nazwisko = nazwisko;
- }
- get imie(){
- return this._imie;
- }
- get nazwisko(){
- return this._nazwisko;
- }
- }
- class Klient extends Czlowiek {
- static stworzKlienta(czlowiek, id, adres, dataUrodzenia, dataWaznosciKarnetu, telefon) {
- return new Klient(czlowiek.imie, czlowiek.nazwisko, id, adres, dataUrodzenia, dataWaznosciKarnetu, telefon)
- }
- constructor(imie, nazwisko, id, adres, dataUrodzenia, dataWaznosciKarnetu, telefon){
- super(imie, nazwisko);
- if(typeof(id) !== "number")
- throw "id != number";
- if(!(dataUrodzenia instanceof Date))
- throw "dataUrodzenia != Date";
- this.adres = adres;
- this.dataWaznosciKarnetu = dataWaznosciKarnetu;
- this.telefon = telefon;
- this._id = id;
- this._adres = adres;
- this._dataUrodzenia = dataUrodzenia;
- this._dataWaznosciKarnetu = dataWaznosciKarnetu;
- this._telefon = telefon;
- }
- get id() {
- return this._id;
- }
- get adres() {
- return this._adres;
- }
- get dataUrodzenia() {
- return this._dataUrodzenia;
- }
- get dataWaznosciKarnetu() {
- return this._dataWaznosciKarnetu;
- }
- get telefon() {
- return this._telefon;
- }
- set adres(value) {
- if(typeof(value) !== "string")
- throw "adres != string";
- this._adres = value;
- }
- set dataWaznosciKarnetu(value) {
- if(!(value instanceof Date))
- throw "value != Date";
- this._dataWaznosciKarnetu = value;
- }
- set telefon(value) {
- if(typeof(value) !== "string")
- throw "value != string";
- this._telefon = value;
- }
- }
- function test() {
- let czlowiek = new Czlowiek("Jan", "Kowalski");
- console.log("człowiek", czlowiek);
- let nowyKlient = Klient.stworzKlienta(czlowiek, 1,"Warszawa", new Date("1990-04-10"), new Date("2020-12-10"), "+48 123 456 789");
- console.log("klient", nowyKlient);
- }
- test();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement