js/src/tests/js1_3/inherit/proto_10.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

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6
michael@0 7 /**
michael@0 8 File Name: proto_10.js
michael@0 9 Section:
michael@0 10 Description: Determining Instance Relationships
michael@0 11
michael@0 12 This tests Object Hierarchy and Inheritance, as described in the document
michael@0 13 Object Hierarchy and Inheritance in JavaScript, last modified on 12/18/97
michael@0 14 15:19:34 on http://devedge.netscape.com/. Current URL:
michael@0 15 http://devedge.netscape.com/docs/manuals/communicator/jsobj/contents.htm
michael@0 16
michael@0 17 This tests the syntax ObjectName.prototype = new PrototypeObject using the
michael@0 18 Employee example in the document referenced above.
michael@0 19
michael@0 20 Author: christine@netscape.com
michael@0 21 Date: 12 november 1997
michael@0 22 */
michael@0 23
michael@0 24 var SECTION = "proto_10";
michael@0 25 var VERSION = "JS1_3";
michael@0 26 var TITLE = "Determining Instance Relationships";
michael@0 27
michael@0 28 startTest();
michael@0 29 writeHeaderToLog( SECTION + " "+ TITLE);
michael@0 30
michael@0 31 function InstanceOf( object, constructor ) {
michael@0 32 return object instanceof constructor;
michael@0 33 }
michael@0 34 function Employee ( name, dept ) {
michael@0 35 this.name = name || "";
michael@0 36 this.dept = dept || "general";
michael@0 37 }
michael@0 38
michael@0 39 function Manager () {
michael@0 40 this.reports = [];
michael@0 41 }
michael@0 42 Manager.prototype = new Employee();
michael@0 43
michael@0 44 function WorkerBee ( name, dept, projs ) {
michael@0 45 this.base = Employee;
michael@0 46 this.base( name, dept)
michael@0 47 this.projects = projs || new Array();
michael@0 48 }
michael@0 49 WorkerBee.prototype = new Employee();
michael@0 50
michael@0 51 function SalesPerson () {
michael@0 52 this.dept = "sales";
michael@0 53 this.quota = 100;
michael@0 54 }
michael@0 55 SalesPerson.prototype = new WorkerBee();
michael@0 56
michael@0 57 function Engineer ( name, projs, machine ) {
michael@0 58 this.base = WorkerBee;
michael@0 59 this.base( name, "engineering", projs )
michael@0 60 this.machine = machine || "";
michael@0 61 }
michael@0 62 Engineer.prototype = new WorkerBee();
michael@0 63
michael@0 64 var pat = new Engineer();
michael@0 65
michael@0 66 new TestCase( SECTION,
michael@0 67 "InstanceOf( pat, Engineer )",
michael@0 68 true,
michael@0 69 InstanceOf( pat, Engineer ) );
michael@0 70
michael@0 71 new TestCase( SECTION,
michael@0 72 "InstanceOf( pat, WorkerBee )",
michael@0 73 true,
michael@0 74 InstanceOf( pat, WorkerBee ) );
michael@0 75
michael@0 76 new TestCase( SECTION,
michael@0 77 "InstanceOf( pat, Employee )",
michael@0 78 true,
michael@0 79 InstanceOf( pat, Employee ) );
michael@0 80
michael@0 81 new TestCase( SECTION,
michael@0 82 "InstanceOf( pat, Object )",
michael@0 83 true,
michael@0 84 InstanceOf( pat, Object ) );
michael@0 85
michael@0 86 new TestCase( SECTION,
michael@0 87 "InstanceOf( pat, SalesPerson )",
michael@0 88 false,
michael@0 89 InstanceOf ( pat, SalesPerson ) );
michael@0 90 test();

mercurial