June 5, 2002 - Writing a Classic Base Class | WebReference

June 5, 2002 - Writing a Classic Base Class

Yehuda Shiran June 5, 2002
Writing a Classic Base Class
Tips: June 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

A base class in JScript .NET is like any other classes. You cannot tell a base class from a class that is not extended by other classes. Here is the Employee class, which we can use as a base class for other classes, such as the Manager class (not shown here):

  class Employee{
    var name : String;
    var address : String;
  
    function Employee(empName : String){
      this.name = empName;
    }
 
    function printMailingLabel() {
      print(name);
      print(address);
    }
  }
Let's create an instance of the Employee class, and set its name and address:

  var Bob : Employee = new Employee("Bob Smith");
  Bob.address = "2010 University Avenue, Palo Alto, CA 94301";
The command Bob.printMailingLabel() will yield the following output:

  Bob Smith
  2010 University Avenue, Palo Alto, CA 94301
To learn more about JScript .NET, go to Column 110, JScript .NET, Part IV: Inheritance.