|
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_2.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 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_2"; |
|
25 var VERSION = "JS1_3"; |
|
26 var TITLE = "new PrototypeObject"; |
|
27 |
|
28 startTest(); |
|
29 writeHeaderToLog( SECTION + " "+ TITLE); |
|
30 |
|
31 function Employee () { |
|
32 this.name = ""; |
|
33 this.dept = "general"; |
|
34 } |
|
35 function Manager () { |
|
36 this.reports = []; |
|
37 } |
|
38 Manager.prototype = new Employee(); |
|
39 |
|
40 function WorkerBee () { |
|
41 this.projects = new Array(); |
|
42 } |
|
43 |
|
44 WorkerBee.prototype = new Employee; |
|
45 |
|
46 function SalesPerson () { |
|
47 this.dept = "sales"; |
|
48 this.quota = 100; |
|
49 } |
|
50 SalesPerson.prototype = new WorkerBee; |
|
51 |
|
52 function Engineer () { |
|
53 this.dept = "engineering"; |
|
54 this.machine = ""; |
|
55 } |
|
56 Engineer.prototype = new WorkerBee; |
|
57 |
|
58 |
|
59 var employee = new Employee(); |
|
60 var manager = new Manager(); |
|
61 var workerbee = new WorkerBee(); |
|
62 var salesperson = new SalesPerson(); |
|
63 var engineer = new Engineer(); |
|
64 |
|
65 new TestCase( SECTION, |
|
66 "employee.__proto__ == Employee.prototype", |
|
67 true, |
|
68 employee.__proto__ == Employee.prototype ); |
|
69 |
|
70 new TestCase( SECTION, |
|
71 "manager.__proto__ == Manager.prototype", |
|
72 true, |
|
73 manager.__proto__ == Manager.prototype ); |
|
74 |
|
75 new TestCase( SECTION, |
|
76 "workerbee.__proto__ == WorkerBee.prototype", |
|
77 true, |
|
78 workerbee.__proto__ == WorkerBee.prototype ); |
|
79 |
|
80 new TestCase( SECTION, |
|
81 "salesperson.__proto__ == SalesPerson.prototype", |
|
82 true, |
|
83 salesperson.__proto__ == SalesPerson.prototype ); |
|
84 |
|
85 new TestCase( SECTION, |
|
86 "engineer.__proto__ == Engineer.prototype", |
|
87 true, |
|
88 engineer.__proto__ == Engineer.prototype ); |
|
89 |
|
90 test(); |
|
91 |