js/src/tests/js1_3/inherit/proto_4.js

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

     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/. */
     7 /**
     8    File Name:          proto_4.js
     9    Section:
    10    Description:        new PrototypeObject
    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
    17    This tests the syntax ObjectName.prototype = new PrototypeObject using the
    18    Employee example in the document referenced above.
    20    If you add a property to an object in the prototype chain, instances of
    21    objects that derive from that prototype should inherit that property, even
    22    if they were instatiated after the property was added to the prototype object.
    25    Author:             christine@netscape.com
    26    Date:               12 november 1997
    27 */
    29 var SECTION = "proto_3";
    30 var VERSION = "JS1_3";
    31 var TITLE   = "Adding properties to the prototype";
    33 startTest();
    34 writeHeaderToLog( SECTION + " "+ TITLE);
    36 function Employee () {
    37   this.name = "";
    38   this.dept = "general";
    39 }
    40 function Manager () {
    41   this.reports = [];
    42 }
    43 Manager.prototype = new Employee();
    45 function WorkerBee () {
    46   this.projects = new Array();
    47 }
    49 WorkerBee.prototype = new Employee();
    51 function SalesPerson () {
    52   this.dept = "sales";
    53   this.quota = 100;
    54 }
    55 SalesPerson.prototype = new WorkerBee();
    57 function Engineer () {
    58   this.dept = "engineering";
    59   this.machine = "";
    60 }
    61 Engineer.prototype = new WorkerBee();
    63 var jim = new Employee();
    64 var terry = new Engineer();
    65 var sean = new SalesPerson();
    66 var wally = new Manager();
    68 Employee.prototype.specialty = "none";
    70 var pat = new Employee();
    71 var leslie = new Engineer();
    72 var bubbles = new SalesPerson();
    73 var furry = new Manager();
    75 Engineer.prototype.specialty = "code";
    77 var chris = new Engineer();
    80 new TestCase( SECTION,
    81 	      "jim = new Employee(); jim.specialty",
    82 	      "none",
    83 	      jim.specialty );
    85 new TestCase( SECTION,
    86 	      "terry = new Engineer(); terry.specialty",
    87 	      "code",
    88 	      terry.specialty );
    90 new TestCase( SECTION,
    91 	      "sean = new SalesPerson(); sean.specialty",
    92 	      "none",
    93 	      sean.specialty );
    95 new TestCase( SECTION,
    96 	      "wally = new Manager(); wally.specialty",
    97 	      "none",
    98 	      wally.specialty );
   100 new TestCase( SECTION,
   101 	      "furry = new Manager(); furry.specialty",
   102 	      "none",
   103 	      furry.specialty );
   105 new TestCase( SECTION,
   106 	      "pat = new Employee(); pat.specialty",
   107 	      "none",
   108 	      pat.specialty );
   110 new TestCase( SECTION,
   111 	      "leslie = new Engineer(); leslie.specialty",
   112 	      "code",
   113 	      leslie.specialty );
   115 new TestCase( SECTION,
   116 	      "bubbles = new SalesPerson(); bubbles.specialty",
   117 	      "none",
   118 	      bubbles.specialty );
   121 new TestCase( SECTION,
   122 	      "chris = new Employee(); chris.specialty",
   123 	      "code",
   124 	      chris.specialty );
   125 test();

mercurial