spacer
Yehuda Shiran June 15, 2002
Using hide
Tips: June 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

Let's look at an example that demonstrates the hide behavior. The class FirstBase has two methods: pitcher() and hitter(), each printing a unique message:

class FirstBase {
    function pitcher() { print("I am a pitcher on first base"); }
    function hitter() { print("I am a hitter on first base"); }
  }
Let's define a derived class now. It redefines both the pitcher() and the hitter() methods. The pitcher() method will be marked as hide, and the hitter() function will be marked as override:

  class SecondBase extends FirstBase {
    hide     function pitcher() { print("I am a pitcher on second base"); }
    override function hitter() { print("I am a hitter on second base"); }
  }
Let's create an instance of the derived class, SecondBase:

  player : SecondBase = new SecondBase;
and call his pitcher() and hitter() methods:

  player.pitcher();
  player.hitter();
The output should reflect the default of overriding the base methods:

  I am a pitcher on second base
  I am a hitter on second base
But if we set a variable of type FirstBase, say player2, pointing to player, we get different results. The override function of the derived class SecondBase indeed overrides the base class method. The hide function of the derived class, though, does not override the base class, when the variable is of the base class type. Here is the code:

  player2 : FirstBase = player;
  player2.pitcher();
  player2.hitter();
and here is the output:

  I am a pitcher on first base
  I am a hitter on second base
To learn more about JScript .NET, go to Column 110, JScript .NET, Part IV: Inheritance.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business