|
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_6.js |
|
9 Section: |
|
10 Description: Logical OR || in constructors |
|
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 This tests the logical OR opererator || syntax in constructors. |
|
21 |
|
22 Author: christine@netscape.com |
|
23 Date: 12 november 1997 |
|
24 */ |
|
25 |
|
26 var SECTION = "proto_6"; |
|
27 var VERSION = "JS1_3"; |
|
28 var TITLE = "Logical OR || in constructors"; |
|
29 |
|
30 startTest(); |
|
31 writeHeaderToLog( SECTION + " "+ TITLE); |
|
32 |
|
33 function Employee ( name, dept ) { |
|
34 this.name = name || ""; |
|
35 this.dept = dept || "general"; |
|
36 } |
|
37 function Manager () { |
|
38 this.reports = []; |
|
39 } |
|
40 Manager.prototype = new Employee(); |
|
41 |
|
42 function WorkerBee ( name, dept, projs ) { |
|
43 this.base = Employee; |
|
44 this.base( name, dept) |
|
45 this.projects = projs || new Array(); |
|
46 } |
|
47 |
|
48 WorkerBee.prototype = new Employee(); |
|
49 |
|
50 function SalesPerson () { |
|
51 this.dept = "sales"; |
|
52 this.quota = 100; |
|
53 } |
|
54 SalesPerson.prototype = new WorkerBee(); |
|
55 |
|
56 function Engineer ( name, projs, machine ) { |
|
57 this.base = WorkerBee; |
|
58 this.base( name, "engineering", projs ) |
|
59 this.machine = machine || ""; |
|
60 } |
|
61 Engineer.prototype = new WorkerBee(); |
|
62 |
|
63 var pat = new Engineer( "Toonces, Pat", |
|
64 ["SpiderMonkey", "Rhino"], |
|
65 "indy" ); |
|
66 |
|
67 var les = new WorkerBee( "Morris, Les", |
|
68 "Training", |
|
69 ["Hippo"] ) |
|
70 |
|
71 var terry = new Employee( "Boomberi, Terry", |
|
72 "Marketing" ); |
|
73 |
|
74 // Pat, the Engineer |
|
75 |
|
76 new TestCase( SECTION, |
|
77 "pat.name", |
|
78 "Toonces, Pat", |
|
79 pat.name ); |
|
80 |
|
81 new TestCase( SECTION, |
|
82 "pat.dept", |
|
83 "engineering", |
|
84 pat.dept ); |
|
85 |
|
86 new TestCase( SECTION, |
|
87 "pat.projects.length", |
|
88 2, |
|
89 pat.projects.length ); |
|
90 |
|
91 new TestCase( SECTION, |
|
92 "pat.projects[0]", |
|
93 "SpiderMonkey", |
|
94 pat.projects[0] ); |
|
95 |
|
96 new TestCase( SECTION, |
|
97 "pat.projects[1]", |
|
98 "Rhino", |
|
99 pat.projects[1] ); |
|
100 |
|
101 new TestCase( SECTION, |
|
102 "pat.machine", |
|
103 "indy", |
|
104 pat.machine ); |
|
105 |
|
106 |
|
107 // Les, the WorkerBee |
|
108 |
|
109 new TestCase( SECTION, |
|
110 "les.name", |
|
111 "Morris, Les", |
|
112 les.name ); |
|
113 |
|
114 new TestCase( SECTION, |
|
115 "les.dept", |
|
116 "Training", |
|
117 les.dept ); |
|
118 |
|
119 new TestCase( SECTION, |
|
120 "les.projects.length", |
|
121 1, |
|
122 les.projects.length ); |
|
123 |
|
124 new TestCase( SECTION, |
|
125 "les.projects[0]", |
|
126 "Hippo", |
|
127 les.projects[0] ); |
|
128 |
|
129 // Terry, the Employee |
|
130 new TestCase( SECTION, |
|
131 "terry.name", |
|
132 "Boomberi, Terry", |
|
133 terry.name ); |
|
134 |
|
135 new TestCase( SECTION, |
|
136 "terry.dept", |
|
137 "Marketing", |
|
138 terry.dept ); |
|
139 test(); |
|
140 |