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