1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
---|
2 | <html xmlns="http://www.w3.org/1999/xhtml"> |
---|
3 | <head> |
---|
4 | <title></title> |
---|
5 | <script type="text/javascript" language="javascript" src="library/jquery-1.4.1.js"></script> |
---|
6 | <script type="text/javascript" language="javascript" src="library/jquery.class.js"></script> |
---|
7 | <script type="text/javascript" language="javascript"> |
---|
8 | $(function() { |
---|
9 | // person class |
---|
10 | var Person = $.Class.create({ |
---|
11 | // constructor |
---|
12 | initialize: function(name, family, father_name) { |
---|
13 | this._name = name; |
---|
14 | this._family = family; |
---|
15 | this._father_name = father_name; |
---|
16 | }, |
---|
17 | // methods |
---|
18 | toString: function() { |
---|
19 | return this.property('Name') + ' ' + this.property('Family') + ' Son of ' + this.property('FatherName') + ' ' + this.property('Family'); |
---|
20 | } |
---|
21 | }, { |
---|
22 | // properties |
---|
23 | getset: [['Name', '_name'], ['Family', '_family'], ['FatherName', '_father_name']] |
---|
24 | }); |
---|
25 | var john = new Person('John', 'Foster', 'Bill'); |
---|
26 | alert(john); |
---|
27 | |
---|
28 | // student class |
---|
29 | var Student = $.Class.create(Person, { |
---|
30 | // constructor |
---|
31 | initialize: function(name, family, father_name, student_code) { |
---|
32 | this.parent(arguments.callee, arguments); |
---|
33 | this._student_code = student_code; |
---|
34 | }, |
---|
35 | // methods |
---|
36 | toString: function() { |
---|
37 | return this.property('Name') + ' ' + this.property('Family') + ' Son of ' + this.property('FatherName') + ' ' + this.property('Family') + ' Student Code is:' + this.property('StudentCode'); |
---|
38 | } |
---|
39 | }, { |
---|
40 | // properties |
---|
41 | getset: [['StudentCode', '_student_code']] |
---|
42 | }); |
---|
43 | var johnStudent = new Student('John', 'Foster', 'Bill', 1001); |
---|
44 | alert(johnStudent); |
---|
45 | |
---|
46 | // employee class |
---|
47 | var Employee = $.Class.create(Person, { |
---|
48 | // properties |
---|
49 | getEmployeeCode: function() { return this._employee_code; }, |
---|
50 | setEmployeeCode: function() { this._employee_code = arguments[0]; }, |
---|
51 | // constructor |
---|
52 | initialize: function(name, family, father_name, employee_code) { |
---|
53 | this.parent(arguments.callee, arguments); |
---|
54 | this._employee_code = employee_code; |
---|
55 | }, |
---|
56 | // methods |
---|
57 | toString: function() { |
---|
58 | return this.property('Name') + ' ' + this.property('Family') + ' Son of ' + this.property('FatherName') + ' ' + this.property('Family') + ' Employee Code is:' + this.property('EmployeeCode'); |
---|
59 | } |
---|
60 | }); |
---|
61 | var johnEmployee = new Employee('John', 'Foster', 'Bill', 5001); |
---|
62 | alert(johnEmployee); |
---|
63 | |
---|
64 | // base car class |
---|
65 | var BaseCar = $.Class.create({ |
---|
66 | // constructor |
---|
67 | initialize: function(name, model) { |
---|
68 | this._name = name; |
---|
69 | this._model = model; |
---|
70 | }, |
---|
71 | // methods |
---|
72 | toString: function() { |
---|
73 | return this.property('Name') + ' ' + this.property('Model'); |
---|
74 | } |
---|
75 | }, { |
---|
76 | // properties |
---|
77 | getset: [['Name', '_name'], ['Model', '_model']], |
---|
78 | // settings |
---|
79 | abstract: true |
---|
80 | }); |
---|
81 | try { |
---|
82 | var toyota = new BaseCar('Toyota', '2008'); |
---|
83 | alert(toyota); |
---|
84 | } catch (ex) { |
---|
85 | alert(ex); |
---|
86 | } |
---|
87 | |
---|
88 | // car class |
---|
89 | var Car = $.Class.create(BaseCar); |
---|
90 | var toyota = new Car('Toyota', '2008'); |
---|
91 | alert(toyota); |
---|
92 | |
---|
93 | // computer interface |
---|
94 | var computerInterface = new $.Interface(); |
---|
95 | computerInterface.attributes = ['_name', '_prosessor']; |
---|
96 | computerInterface.properties = ['Name', 'Prosessor']; |
---|
97 | computerInterface.methods = ['turnOn', 'turnOff']; |
---|
98 | |
---|
99 | try { |
---|
100 | var computerWidthError = $.Class.create({ |
---|
101 | // constructor |
---|
102 | initialize: function(name, prosessor) { |
---|
103 | this._name = name; |
---|
104 | this._prosessor = prosessor; |
---|
105 | }, |
---|
106 | // methods |
---|
107 | toString: function() { |
---|
108 | return this.property('Name') + ' ' + this.property('Prosessor'); |
---|
109 | } |
---|
110 | }, { |
---|
111 | // properties |
---|
112 | getset: [['Name', '_name']], |
---|
113 | // settings |
---|
114 | implements: [computerInterface] // can be more than one |
---|
115 | }); |
---|
116 | } catch (ex) { |
---|
117 | alert(ex); |
---|
118 | } |
---|
119 | |
---|
120 | var computer = $.Class.create({ |
---|
121 | // attributes |
---|
122 | _name: null, |
---|
123 | _prosessor: null, |
---|
124 | // constructor |
---|
125 | initialize: function(name, prosessor) { |
---|
126 | this._name = name; |
---|
127 | this._prosessor = prosessor; |
---|
128 | }, |
---|
129 | // methods |
---|
130 | toString: function() { |
---|
131 | return this.property('Name') + ' ' + this.property('Prosessor'); |
---|
132 | }, |
---|
133 | turnOn: function() { |
---|
134 | alert("i'm on"); |
---|
135 | }, |
---|
136 | turnOff: function() { |
---|
137 | alert("i'm off"); |
---|
138 | } |
---|
139 | }, { |
---|
140 | // properties |
---|
141 | getset: [['Name', '_name'], ['Prosessor', '_prosessor']], |
---|
142 | // settings |
---|
143 | implements: [computerInterface] // can be more than one |
---|
144 | }); |
---|
145 | var pc = new computer('Pc', 'Intel'); |
---|
146 | pc.turnOn(); |
---|
147 | pc.turnOff(); |
---|
148 | |
---|
149 | // person module |
---|
150 | var Mine = $.Class.create({ |
---|
151 | // methods |
---|
152 | Hi: function() { |
---|
153 | alert('Hi, My name is hassan jodat shandi'); |
---|
154 | } |
---|
155 | }, { |
---|
156 | // settings |
---|
157 | module: 'Hwt.Test.Hassan' |
---|
158 | }); |
---|
159 | Hwt.Test.Hassan.Hi(); |
---|
160 | }); |
---|
161 | </script> |
---|
162 | </head> |
---|
163 | <body> |
---|
164 | </body> |
---|
165 | </html> |
---|