|
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_11.js |
|
9 Section: |
|
10 Description: Global Information 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 Author: christine@netscape.com |
|
21 Date: 12 november 1997 |
|
22 */ |
|
23 |
|
24 var SECTION = "proto_11"; |
|
25 var VERSION = "JS1_3"; |
|
26 var TITLE = "Global Information in Constructors"; |
|
27 |
|
28 startTest(); |
|
29 writeHeaderToLog( SECTION + " "+ TITLE); |
|
30 |
|
31 var idCounter = 1; |
|
32 |
|
33 |
|
34 function Employee ( name, dept ) { |
|
35 this.name = name || ""; |
|
36 this.dept = dept || "general"; |
|
37 this.id = idCounter++; |
|
38 } |
|
39 function Manager () { |
|
40 this.reports = []; |
|
41 } |
|
42 Manager.prototype = new Employee(); |
|
43 |
|
44 function WorkerBee ( name, dept, projs ) { |
|
45 this.base = Employee; |
|
46 this.base( name, dept) |
|
47 this.projects = projs || new Array(); |
|
48 } |
|
49 WorkerBee.prototype = new Employee(); |
|
50 |
|
51 function SalesPerson () { |
|
52 this.dept = "sales"; |
|
53 this.quota = 100; |
|
54 } |
|
55 SalesPerson.prototype = new WorkerBee(); |
|
56 |
|
57 function Engineer ( name, projs, machine ) { |
|
58 this.base = WorkerBee; |
|
59 this.base( name, "engineering", projs ) |
|
60 this.machine = machine || ""; |
|
61 } |
|
62 Engineer.prototype = new WorkerBee(); |
|
63 |
|
64 var pat = new Employee( "Toonces, Pat", "Tech Pubs" ) |
|
65 var terry = new Employee( "O'Sherry Terry", "Marketing" ); |
|
66 |
|
67 var les = new Engineer( "Morris, Les", new Array("JavaScript"), "indy" ); |
|
68 |
|
69 new TestCase( SECTION, |
|
70 "pat.id", |
|
71 5, |
|
72 pat.id ); |
|
73 |
|
74 new TestCase( SECTION, |
|
75 "terry.id", |
|
76 6, |
|
77 terry.id ); |
|
78 |
|
79 new TestCase( SECTION, |
|
80 "les.id", |
|
81 7, |
|
82 les.id ); |
|
83 |
|
84 |
|
85 test(); |
|
86 |