01/Trieda3.html
1 <?xml version="1.0" encoding="windows-1250"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3 "DTD/xhtml1-strict.dtd">
4 <html>
5 <head>
6 <title>PC Space JavaScript a OOP</title>
7 <meta http-equiv="Author" content="Imrich BURANSKY" />
8 <meta http-equiv="Content-Type" content="text/html; charset=Windows-1250" />
9 <script type="text/javascript" >
10 // Definicia zakladenej triedy
11 function CKniha(autor, nazev, stran)
12 {
13 // Vlastnosti
14 this.autor = autor;
15 this.nazev = nazev;
16 this.stran = stran;
17 // Metody
18 this.DajText = DajText;
19 // Definicia metody
20 function DajText (bHTML)
21 {
22 sText = "";
23 sBR = "\n";
24 if (bHTML)
25 { sBR = "<br />\n";
26 sText ="<h3>Kniha</h3>";
27 }
28 sText+="autor: " + this.autor + sBR;
29 sText+="nazev: " + this.nazev + sBR;
30 sText+="stran: " + this.stran + sBR;
31 return sText;
32 }
33 }
34 // Definovanie rozsirenej triedy
35 function CKnihaSCenou (autor, nazev, stran, cena)
36 {
37 // Urcenie rodica
38 this.rodic = CKniha;
39 this.rodic (autor, nazev, stran);
40 // Rozsirenie o novu vlastnost
41 this.cena = cena;
42 // Rozsirenie o novu metodu
43 this.DajTextSCenou = TextSCenou;
44 // Definicia novej metody
45 function TextSCenou (bHTML)
46 {
47 // Vyuzitie funkcie rodica
48 sText=this.DajText(bHTML);
49 // Doplnenie vypisu ceny
50 sBR = "\n";
51 if (bHTML) sBR = "<br />\n";
52 sText+="cena: " + this.cena + sBR;
53 return sText;
54 }
55 }
56 // Prikaz pre pouzitie prototypu - rodica
57 CKnihaSCenou.prototype = CKniha;
58
59 </script>
60 </head>
61 <body>
62 <script type="text/javascript" >
63 // Vytvorenie objektu
64 Kniha = new CKnihaSCenou("Imrich Buranský",
65 "HTML a DHTML Hotová řešení",
66 257,
67 239 );
68 // Pouzitie objektu
69 document.write(Kniha.DajText(true));
70 document.write("<br />\n");
71 document.write(Kniha.DajText(false));
72 document.write(Kniha.DajTextSCenou(true));
73 document.write("<br />\n");
74 document.write(Kniha.DajTextSCenou(false));
75
76 </script>
77 </body>
78 </html>
79
80 <!-- ***** Výsledok *****
81
82 Kniha
83 autor: Imrich Buranský
84 nazev: HTML a DHTML Hotová řešení
85 stran: 257
86
87 autor: Imrich Buranský nazev: HTML a DHTML Hotová řešení stran: 257
88
89 Kniha
90 autor: Imrich Buranský
91 nazev: HTML a DHTML Hotová řešení
92 stran: 257
93 cena: 239
94
95 autor: Imrich Buranský nazev: HTML a DHTML Hotová řešení stran: 257 cena: 239
96 -->