Debian Codegraph @

rhino/testsrc/tests/js1_3/inherit/proto_4.js

raw symbols SCIP
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 gTestfile = 'proto_4.js';
7
8 /**
9 File Name: proto_4.js
10 Section:
11 Description: new PrototypeObject
12
13 This tests Object Hierarchy and Inheritance, as described in the document
14 Object Hierarchy and Inheritance in JavaScript, last modified on 12/18/97
15 15:19:34 on http://devedge.netscape.com/. Current URL:
16 http://devedge.netscape.com/docs/manuals/communicator/jsobj/contents.htm
17
18 This tests the syntax ObjectName.prototype = new PrototypeObject using the
19 Employee example in the document referenced above.
20
21 If you add a property to an object in the prototype chain, instances of
22 objects that derive from that prototype should inherit that property, even
23 if they were instatiated after the property was added to the prototype object.
24
25
26 Author: [email protected]
27 Date: 12 november 1997
28 */
29
30 var SECTION = "proto_3";
31 var VERSION = "JS1_3";
32 var TITLE = "Adding properties to the prototype";
33
34 startTest();
35 writeHeaderToLog( SECTION + " "+ TITLE);
36
37 function Employee () {
38 this.name = "";
39 this.dept = "general";
40 }
41 function Manager () {
42 this.reports = [];
43 }
44 Manager.prototype = new Employee();
45
46 function WorkerBee () {
47 this.projects = new Array();
48 }
49
50 WorkerBee.prototype = new Employee();
51
52 function SalesPerson () {
53 this.dept = "sales";
54 this.quota = 100;
55 }
56 SalesPerson.prototype = new WorkerBee();
57
58 function Engineer () {
59 this.dept = "engineering";
60 this.machine = "";
61 }
62 Engineer.prototype = new WorkerBee();
63
64 var jim = new Employee();
65 var terry = new Engineer();
66 var sean = new SalesPerson();
67 var wally = new Manager();
68
69 Employee.prototype.specialty = "none";
70
71 var pat = new Employee();
72 var leslie = new Engineer();
73 var bubbles = new SalesPerson();
74 var furry = new Manager();
75
76 Engineer.prototype.specialty = "code";
77
78 var chris = new Engineer();
79
80
81 new TestCase( SECTION,
82 "jim = new Employee(); jim.specialty",
83 "none",
84 jim.specialty );
85
86 new TestCase( SECTION,
87 "terry = new Engineer(); terry.specialty",
88 "code",
89 terry.specialty );
90
91 new TestCase( SECTION,
92 "sean = new SalesPerson(); sean.specialty",
93 "none",
94 sean.specialty );
95
96 new TestCase( SECTION,
97 "wally = new Manager(); wally.specialty",
98 "none",
99 wally.specialty );
100
101 new TestCase( SECTION,
102 "furry = new Manager(); furry.specialty",
103 "none",
104 furry.specialty );
105
106 new TestCase( SECTION,
107 "pat = new Employee(); pat.specialty",
108 "none",
109 pat.specialty );
110
111 new TestCase( SECTION,
112 "leslie = new Engineer(); leslie.specialty",
113 "code",
114 leslie.specialty );
115
116 new TestCase( SECTION,
117 "bubbles = new SalesPerson(); bubbles.specialty",
118 "none",
119 bubbles.specialty );
120
121
122 new TestCase( SECTION,
123 "chris = new Employee(); chris.specialty",
124 "code",
125 chris.specialty );
126 test();