Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="pl" dir="ltr">
- <head>
- <meta charset="utf-8">
- <title>JavaScript - obiekty i klasy</title>
- <script type="text/javascript">
- class Samochod {
- constructor(marka, model, rocznik, cena) {
- this.marka = marka;
- this.model = model;
- this.rocznik = rocznik;
- this.cena = cena;
- }
- wejdz() {
- document.write("wszedł do samochodu ... ");
- }
- wyjdz() {
- document.write("wyszedł z samochodu ... ");
- }
- }
- class Silnik extends Samochod {
- constructor(typ, obroty) {
- super();
- this.typ = typ;
- this.obroty = obroty;
- }
- zwiekszObroty() {
- this.obroty = this.obroty+100;
- }
- zmniejszObroty() {
- this.obroty = this.obroty-100;
- }
- }
- class EGR extends Silnik {
- otworzZaworEGR() {
- document.write("EGR otwarty ... ");
- }
- zamknijZaworEGR() {
- document.write("EGR zamknięty ... ");
- }
- }
- const osoba = {
- imie: "Jan",
- nazwisko: "Kowalski",
- wiek: 24
- }
- function Samolot(producent, model, oznaczenie, zasieg) {
- this.producent = producent;
- this.model = model;
- this.oznaczenie = oznaczenie;
- this.zasieg = zasieg;
- this.liczba_silnikow = 2;
- }
- let lokomotywa = {
- nazwa: 'lokomotywa',
- predkosc: 60,
- max_predkosc: 180,
- typ: 'parowy',
- rok_produkcji: 2019,
- przyspiesz: function() {
- return this.predkosc +=10;
- },
- zwolnij: function() {
- return this.predkosc -=10;
- },
- zatrzymaj: function() {
- return this.predkosc = 0;
- }
- }
- function zmien(){
- delete lokomotywa.predkosc;
- lokomotywa.ciezar = 20;
- lokomotywa.zatrzymaj()
- console.log(lokomotywa);
- }
- function rusz(){
- if (lokomotywa.predkosc <20) {
- lokomotywa.przyspiesz()
- console.log(lokomotywa)
- } else (alert(lokomotywa.predkosc))
- }
- boeing = new Samolot('Boeing Company', 'Boeing 747', '747-8', 14815)
- document.write(boeing.producent, boeing.model)
- porsche = new Samochod('Porsche', '911', '1963', 2000)
- document.write(osoba.imie + ' '+ osoba.nazwisko + porsche.wejdz())
- </script>
- </head>
- <body>
- <center>
- <button type="button" onclick="zmien()">Zmień</button>
- <button type="button" onclick="rusz()">Rusz</button>
- </center>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement