]>
Commit | Line | Data |
---|---|---|
b37bf2e1 A |
1 | /* The contents of this file are subject to the Netscape Public |
2 | * License Version 1.1 (the "License"); you may not use this file | |
3 | * except in compliance with the License. You may obtain a copy of | |
4 | * the License at http://www.mozilla.org/NPL/ | |
5 | * | |
6 | * Software distributed under the License is distributed on an "AS | |
7 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | |
8 | * implied. See the License for the specific language governing | |
9 | * rights and limitations under the License. | |
10 | * | |
11 | * The Original Code is Mozilla Communicator client code, released March | |
12 | * 31, 1998. | |
13 | * | |
14 | * The Initial Developer of the Original Code is Netscape Communications | |
15 | * Corporation. Portions created by Netscape are | |
16 | * Copyright (C) 1998 Netscape Communications Corporation. All | |
17 | * Rights Reserved. | |
18 | * | |
19 | * Contributor(s): | |
20 | * | |
21 | */ | |
22 | /** | |
23 | File Name: proto_7.js | |
24 | Section: | |
25 | Description: Adding Properties to the Prototype Object | |
26 | ||
27 | This tests Object Hierarchy and Inheritance, as described in the document | |
28 | Object Hierarchy and Inheritance in JavaScript, last modified on 12/18/97 | |
29 | 15:19:34 on http://devedge.netscape.com/. Current URL: | |
30 | http://devedge.netscape.com/docs/manuals/communicator/jsobj/contents.htm | |
31 | ||
32 | This tests the syntax ObjectName.prototype = new PrototypeObject using the | |
33 | Employee example in the document referenced above. | |
34 | ||
35 | This tests | |
36 | ||
37 | Author: christine@netscape.com | |
38 | Date: 12 november 1997 | |
39 | */ | |
40 | ||
41 | var SECTION = "proto_6"; | |
42 | var VERSION = "JS1_3"; | |
43 | var TITLE = "Adding properties to the Prototype Object"; | |
44 | ||
45 | startTest(); | |
46 | writeHeaderToLog( SECTION + " "+ TITLE); | |
47 | ||
48 | var testcases = new Array(); | |
49 | ||
50 | function Employee ( name, dept ) { | |
51 | this.name = name || ""; | |
52 | this.dept = dept || "general"; | |
53 | } | |
54 | function WorkerBee ( name, dept, projs ) { | |
55 | this.base = Employee; | |
56 | this.base( name, dept) | |
57 | this.projects = projs || new Array(); | |
58 | } | |
59 | WorkerBee.prototype = new Employee(); | |
60 | ||
61 | function Engineer ( name, projs, machine ) { | |
62 | this.base = WorkerBee; | |
63 | this.base( name, "engineering", projs ) | |
64 | this.machine = machine || ""; | |
65 | } | |
66 | // Engineer.prototype = new WorkerBee(); | |
67 | ||
68 | function test() { | |
69 | for ( tc=0; tc < testcases.length; tc++ ) { | |
70 | testcases[tc].passed = writeTestCaseResult( | |
71 | testcases[tc].expect, | |
72 | testcases[tc].actual, | |
73 | testcases[tc].description +" = "+ | |
74 | testcases[tc].actual ); | |
75 | ||
76 | testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; | |
77 | } | |
78 | stopTest(); | |
79 | return ( testcases ); | |
80 | } | |
81 | var pat = new Engineer( "Toonces, Pat", | |
82 | ["SpiderMonkey", "Rhino"], | |
83 | "indy" ); | |
84 | ||
85 | Employee.prototype.specialty = "none"; | |
86 | ||
87 | ||
88 | // Pat, the Engineer | |
89 | ||
90 | testcases[tc++] = new TestCase( SECTION, | |
91 | "pat.name", | |
92 | "Toonces, Pat", | |
93 | pat.name ); | |
94 | ||
95 | testcases[tc++] = new TestCase( SECTION, | |
96 | "pat.dept", | |
97 | "engineering", | |
98 | pat.dept ); | |
99 | ||
100 | testcases[tc++] = new TestCase( SECTION, | |
101 | "pat.projects.length", | |
102 | 2, | |
103 | pat.projects.length ); | |
104 | ||
105 | testcases[tc++] = new TestCase( SECTION, | |
106 | "pat.projects[0]", | |
107 | "SpiderMonkey", | |
108 | pat.projects[0] ); | |
109 | ||
110 | testcases[tc++] = new TestCase( SECTION, | |
111 | "pat.projects[1]", | |
112 | "Rhino", | |
113 | pat.projects[1] ); | |
114 | ||
115 | testcases[tc++] = new TestCase( SECTION, | |
116 | "pat.machine", | |
117 | "indy", | |
118 | pat.machine ); | |
119 | ||
120 | testcases[tc++] = new TestCase( SECTION, | |
121 | "pat.specialty", | |
122 | void 0, | |
123 | pat.specialty ); | |
124 | ||
125 | test(); |