js/src/tests/js1_3/inherit/proto_12.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:5f658a57943a
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_12.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 No Multiple Inheritance
18
19 Author: christine@netscape.com
20 Date: 12 november 1997
21 */
22
23 var SECTION = "proto_12";
24 var VERSION = "JS1_3";
25 var TITLE = "No Multiple Inheritance";
26
27 startTest();
28 writeHeaderToLog( SECTION + " "+ TITLE);
29
30 function Employee ( name, dept ) {
31 this.name = name || "";
32 this.dept = dept || "general";
33 this.id = idCounter++;
34 }
35 function Manager () {
36 this.reports = [];
37 }
38 Manager.prototype = new Employee();
39
40 function WorkerBee ( name, dept, projs ) {
41 this.base = Employee;
42 this.base( name, dept)
43 this.projects = projs || new Array();
44 }
45 WorkerBee.prototype = new Employee();
46
47 function SalesPerson () {
48 this.dept = "sales";
49 this.quota = 100;
50 }
51 SalesPerson.prototype = new WorkerBee();
52
53 function Hobbyist( hobby ) {
54 this.hobby = hobby || "yodeling";
55 }
56
57 function Engineer ( name, projs, machine, hobby ) {
58 this.base1 = WorkerBee;
59 this.base1( name, "engineering", projs )
60
61 this.base2 = Hobbyist;
62 this.base2( hobby );
63
64 this.projects = projs || new Array();
65 this.machine = machine || "";
66 }
67 Engineer.prototype = new WorkerBee();
68
69 var idCounter = 1;
70
71 var les = new Engineer( "Morris, Les", new Array("JavaScript"), "indy" );
72
73 Hobbyist.prototype.equipment = [ "horn", "mountain", "goat" ];
74
75 new TestCase( SECTION,
76 "les.name",
77 "Morris, Les",
78 les.name );
79
80 new TestCase( SECTION,
81 "les.dept",
82 "engineering",
83 les.dept );
84
85 Array.prototype.getClass = Object.prototype.toString;
86
87 new TestCase( SECTION,
88 "les.projects.getClass()",
89 "[object Array]",
90 les.projects.getClass() );
91
92 new TestCase( SECTION,
93 "les.projects[0]",
94 "JavaScript",
95 les.projects[0] );
96
97 new TestCase( SECTION,
98 "les.machine",
99 "indy",
100 les.machine );
101
102 new TestCase( SECTION,
103 "les.hobby",
104 "yodeling",
105 les.hobby );
106
107 new TestCase( SECTION,
108 "les.equpment",
109 void 0,
110 les.equipment );
111
112 test();

mercurial