michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: File Name: proto_1.js michael@0: Section: michael@0: Description: new PrototypeObject michael@0: michael@0: This tests Object Hierarchy and Inheritance, as described in the document michael@0: Object Hierarchy and Inheritance in JavaScript, last modified on 12/18/97 michael@0: 15:19:34 on http://devedge.netscape.com/. Current URL: michael@0: http://devedge.netscape.com/docs/manuals/communicator/jsobj/contents.htm michael@0: michael@0: This tests the syntax ObjectName.prototype = new PrototypeObject using the michael@0: Employee example in the document referenced above. michael@0: michael@0: Author: christine@netscape.com michael@0: Date: 12 november 1997 michael@0: */ michael@0: michael@0: var SECTION = "proto_1"; michael@0: var VERSION = "JS1_3"; michael@0: var TITLE = "new PrototypeObject"; michael@0: michael@0: startTest(); michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: function Employee () { michael@0: this.name = ""; michael@0: this.dept = "general"; michael@0: } michael@0: function Manager () { michael@0: this.reports = []; michael@0: } michael@0: Manager.prototype = new Employee(); michael@0: michael@0: function WorkerBee () { michael@0: this.projects = new Array(); michael@0: } michael@0: WorkerBee.prototype = new Employee(); michael@0: michael@0: function SalesPerson () { michael@0: this.dept = "sales"; michael@0: this.quota = 100; michael@0: } michael@0: SalesPerson.prototype = new WorkerBee(); michael@0: michael@0: function Engineer () { michael@0: this.dept = "engineering"; michael@0: this.machine = ""; michael@0: } michael@0: Engineer.prototype = new WorkerBee(); michael@0: michael@0: var jim = new Employee(); michael@0: michael@0: new TestCase( SECTION, michael@0: "jim = new Employee(); jim.name", michael@0: "", michael@0: jim.name ); michael@0: michael@0: michael@0: new TestCase( SECTION, michael@0: "jim = new Employee(); jim.dept", michael@0: "general", michael@0: jim.dept ); michael@0: michael@0: var sally = new Manager(); michael@0: michael@0: new TestCase( SECTION, michael@0: "sally = new Manager(); sally.name", michael@0: "", michael@0: sally.name ); michael@0: new TestCase( SECTION, michael@0: "sally = new Manager(); sally.dept", michael@0: "general", michael@0: sally.dept ); michael@0: michael@0: new TestCase( SECTION, michael@0: "sally = new Manager(); sally.reports.length", michael@0: 0, michael@0: sally.reports.length ); michael@0: michael@0: new TestCase( SECTION, michael@0: "sally = new Manager(); typeof sally.reports", michael@0: "object", michael@0: typeof sally.reports ); michael@0: michael@0: var fred = new SalesPerson(); michael@0: michael@0: new TestCase( SECTION, michael@0: "fred = new SalesPerson(); fred.name", michael@0: "", michael@0: fred.name ); michael@0: michael@0: new TestCase( SECTION, michael@0: "fred = new SalesPerson(); fred.dept", michael@0: "sales", michael@0: fred.dept ); michael@0: michael@0: new TestCase( SECTION, michael@0: "fred = new SalesPerson(); fred.quota", michael@0: 100, michael@0: fred.quota ); michael@0: michael@0: new TestCase( SECTION, michael@0: "fred = new SalesPerson(); fred.projects.length", michael@0: 0, michael@0: fred.projects.length ); michael@0: michael@0: var jane = new Engineer(); michael@0: michael@0: new TestCase( SECTION, michael@0: "jane = new Engineer(); jane.name", michael@0: "", michael@0: jane.name ); michael@0: michael@0: new TestCase( SECTION, michael@0: "jane = new Engineer(); jane.dept", michael@0: "engineering", michael@0: jane.dept ); michael@0: michael@0: new TestCase( SECTION, michael@0: "jane = new Engineer(); jane.projects.length", michael@0: 0, michael@0: jane.projects.length ); michael@0: michael@0: new TestCase( SECTION, michael@0: "jane = new Engineer(); jane.machine", michael@0: "", michael@0: jane.machine ); michael@0: michael@0: michael@0: test();