|
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_8.js |
|
9 Section: |
|
10 Description: Adding Properties to the Prototype Object |
|
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_8"; |
|
25 var VERSION = "JS1_3"; |
|
26 var TITLE = "Adding Properties to the Prototype Object"; |
|
27 |
|
28 startTest(); |
|
29 writeHeaderToLog( SECTION + " "+ TITLE); |
|
30 |
|
31 function Employee ( name, dept ) { |
|
32 this.name = name || ""; |
|
33 this.dept = dept || "general"; |
|
34 } |
|
35 function WorkerBee ( name, dept, projs ) { |
|
36 this.base = Employee; |
|
37 this.base( name, dept) |
|
38 this.projects = projs || new Array(); |
|
39 } |
|
40 WorkerBee.prototype = new Employee(); |
|
41 |
|
42 function Engineer ( name, projs, machine ) { |
|
43 this.base = WorkerBee; |
|
44 this.base( name, "engineering", projs ) |
|
45 this.machine = machine || ""; |
|
46 } |
|
47 Engineer.prototype = new WorkerBee(); |
|
48 |
|
49 var pat = new Engineer( "Toonces, Pat", |
|
50 ["SpiderMonkey", "Rhino"], |
|
51 "indy" ); |
|
52 |
|
53 Employee.prototype.specialty = "none"; |
|
54 |
|
55 |
|
56 // Pat, the Engineer |
|
57 |
|
58 new TestCase( SECTION, |
|
59 "pat.name", |
|
60 "Toonces, Pat", |
|
61 pat.name ); |
|
62 |
|
63 new TestCase( SECTION, |
|
64 "pat.dept", |
|
65 "engineering", |
|
66 pat.dept ); |
|
67 |
|
68 new TestCase( SECTION, |
|
69 "pat.projects.length", |
|
70 2, |
|
71 pat.projects.length ); |
|
72 |
|
73 new TestCase( SECTION, |
|
74 "pat.projects[0]", |
|
75 "SpiderMonkey", |
|
76 pat.projects[0] ); |
|
77 |
|
78 new TestCase( SECTION, |
|
79 "pat.projects[1]", |
|
80 "Rhino", |
|
81 pat.projects[1] ); |
|
82 |
|
83 new TestCase( SECTION, |
|
84 "pat.machine", |
|
85 "indy", |
|
86 pat.machine ); |
|
87 |
|
88 new TestCase( SECTION, |
|
89 "pat.specialty", |
|
90 "none", |
|
91 pat.specialty ); |
|
92 |
|
93 test(); |