Home | History | Annotate | Download | only in inherit
      1 /* The contents of this file are subject to the Netscape Public
      2  * License Version 1.1 (the "License"); you may not use this file
      3  * except in compliance with the License. You may obtain a copy of
      4  * the License at http://www.mozilla.org/NPL/
      5  *
      6  * Software distributed under the License is distributed on an "AS
      7  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
      8  * implied. See the License for the specific language governing
      9  * rights and limitations under the License.
     10  *
     11  * The Original Code is Mozilla Communicator client code, released March
     12  * 31, 1998.
     13  *
     14  * The Initial Developer of the Original Code is Netscape Communications
     15  * Corporation. Portions created by Netscape are
     16  * Copyright (C) 1998 Netscape Communications Corporation. All
     17  * Rights Reserved.
     18  *
     19  * Contributor(s):
     20  *
     21  */
     22 /**
     23     File Name:          proto_9.js
     24     Section:
     25     Description:        Local versus Inherited Values
     26 
     27     This tests Object Hierarchy and Inheritance, as described in the document
     28     Object Hierarchy and Inheritance in JavaScript, last modified on 12/18/97
     29     15:19:34 on http://devedge.netscape.com/.  Current URL:
     30     http://devedge.netscape.com/docs/manuals/communicator/jsobj/contents.htm
     31 
     32     This tests the syntax ObjectName.prototype = new PrototypeObject using the
     33     Employee example in the document referenced above.
     34 
     35     This tests
     36 
     37     Author:             christine (at) netscape.com
     38     Date:               12 november 1997
     39 */
     40 
     41     var SECTION = "proto_9";
     42     var VERSION = "JS1_3";
     43     var TITLE   = "Local versus Inherited Values";
     44 
     45     startTest();
     46     writeHeaderToLog( SECTION + " "+ TITLE);
     47 
     48     var testcases = new Array();
     49 
     50 function Employee ( name, dept ) {
     51      this.name = name || "";
     52      this.dept = dept || "general";
     53 }
     54 function WorkerBee ( name, dept, projs ) {
     55     this.projects = new Array();
     56 }
     57 WorkerBee.prototype = new Employee();
     58 
     59 function test() {
     60     for ( tc=0; tc < testcases.length; tc++ ) {
     61         testcases[tc].passed = writeTestCaseResult(
     62                             testcases[tc].expect,
     63                             testcases[tc].actual,
     64                             testcases[tc].description +" = "+
     65                             testcases[tc].actual );
     66 
     67         testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
     68     }
     69     stopTest();
     70     return ( testcases );
     71 }
     72     var pat = new WorkerBee()
     73 
     74     Employee.prototype.specialty = "none";
     75     Employee.prototype.name = "Unknown";
     76 
     77     Array.prototype.getClass = Object.prototype.toString;
     78 
     79     // Pat, the WorkerBee
     80 
     81     testcases[tc++] = new TestCase( SECTION,
     82                                     "pat.name",
     83                                     "",
     84                                     pat.name );
     85 
     86     testcases[tc++] = new TestCase( SECTION,
     87                                     "pat.dept",
     88                                     "general",
     89                                     pat.dept );
     90 
     91     testcases[tc++] = new TestCase( SECTION,
     92                                     "pat.projects.getClass",
     93                                     "[object Array]",
     94                                     pat.projects.getClass() );
     95 
     96     testcases[tc++] = new TestCase( SECTION,
     97                                     "pat.projects.length",
     98                                     0,
     99                                     pat.projects.length );
    100 
    101     test();