|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 |
|
7 /** |
|
8 File Name: proto_1.js |
|
9 Section: |
|
10 Description: new PrototypeObject |
|
11 |
|
12 This tests Object Hierarchy and Inheritance, as described in the document |
|
13 Object Hierarchy and Inheritance in JavaScript, last modified on 12/18/97 |
|
14 15:19:34 on http://devedge.netscape.com/. Current URL: |
|
15 http://devedge.netscape.com/docs/manuals/communicator/jsobj/contents.htm |
|
16 |
|
17 This tests the syntax ObjectName.prototype = new PrototypeObject using the |
|
18 Employee example in the document referenced above. |
|
19 |
|
20 Author: christine@netscape.com |
|
21 Date: 12 november 1997 |
|
22 */ |
|
23 |
|
24 var SECTION = "proto_1"; |
|
25 var VERSION = "JS1_3"; |
|
26 var TITLE = "new PrototypeObject"; |
|
27 |
|
28 startTest(); |
|
29 writeHeaderToLog( SECTION + " "+ TITLE); |
|
30 |
|
31 function Employee () { |
|
32 this.name = ""; |
|
33 this.dept = "general"; |
|
34 } |
|
35 function Manager () { |
|
36 this.reports = []; |
|
37 } |
|
38 Manager.prototype = new Employee(); |
|
39 |
|
40 function WorkerBee () { |
|
41 this.projects = new Array(); |
|
42 } |
|
43 WorkerBee.prototype = new Employee(); |
|
44 |
|
45 function SalesPerson () { |
|
46 this.dept = "sales"; |
|
47 this.quota = 100; |
|
48 } |
|
49 SalesPerson.prototype = new WorkerBee(); |
|
50 |
|
51 function Engineer () { |
|
52 this.dept = "engineering"; |
|
53 this.machine = ""; |
|
54 } |
|
55 Engineer.prototype = new WorkerBee(); |
|
56 |
|
57 var jim = new Employee(); |
|
58 |
|
59 new TestCase( SECTION, |
|
60 "jim = new Employee(); jim.name", |
|
61 "", |
|
62 jim.name ); |
|
63 |
|
64 |
|
65 new TestCase( SECTION, |
|
66 "jim = new Employee(); jim.dept", |
|
67 "general", |
|
68 jim.dept ); |
|
69 |
|
70 var sally = new Manager(); |
|
71 |
|
72 new TestCase( SECTION, |
|
73 "sally = new Manager(); sally.name", |
|
74 "", |
|
75 sally.name ); |
|
76 new TestCase( SECTION, |
|
77 "sally = new Manager(); sally.dept", |
|
78 "general", |
|
79 sally.dept ); |
|
80 |
|
81 new TestCase( SECTION, |
|
82 "sally = new Manager(); sally.reports.length", |
|
83 0, |
|
84 sally.reports.length ); |
|
85 |
|
86 new TestCase( SECTION, |
|
87 "sally = new Manager(); typeof sally.reports", |
|
88 "object", |
|
89 typeof sally.reports ); |
|
90 |
|
91 var fred = new SalesPerson(); |
|
92 |
|
93 new TestCase( SECTION, |
|
94 "fred = new SalesPerson(); fred.name", |
|
95 "", |
|
96 fred.name ); |
|
97 |
|
98 new TestCase( SECTION, |
|
99 "fred = new SalesPerson(); fred.dept", |
|
100 "sales", |
|
101 fred.dept ); |
|
102 |
|
103 new TestCase( SECTION, |
|
104 "fred = new SalesPerson(); fred.quota", |
|
105 100, |
|
106 fred.quota ); |
|
107 |
|
108 new TestCase( SECTION, |
|
109 "fred = new SalesPerson(); fred.projects.length", |
|
110 0, |
|
111 fred.projects.length ); |
|
112 |
|
113 var jane = new Engineer(); |
|
114 |
|
115 new TestCase( SECTION, |
|
116 "jane = new Engineer(); jane.name", |
|
117 "", |
|
118 jane.name ); |
|
119 |
|
120 new TestCase( SECTION, |
|
121 "jane = new Engineer(); jane.dept", |
|
122 "engineering", |
|
123 jane.dept ); |
|
124 |
|
125 new TestCase( SECTION, |
|
126 "jane = new Engineer(); jane.projects.length", |
|
127 0, |
|
128 jane.projects.length ); |
|
129 |
|
130 new TestCase( SECTION, |
|
131 "jane = new Engineer(); jane.machine", |
|
132 "", |
|
133 jane.machine ); |
|
134 |
|
135 |
|
136 test(); |