spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column111


JScript .NET, Part V: Polymorphism

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

The Object Type

When a new class inherits from a base class, it gets all the base's members. You cannot get rid of these members. You can do one of the three: accept, hide, or override them. The default is to accept them. You accept them by refraining from their redefinition in the derived class. Simply put, do not define a derived class's member with the same name as a base class's member. When you do redefine a base member, you override the base class's member by default; this is how you override a base class. You can reflect the override by adding override to the member definition, as we have shown in Column 110. When you override a member, the behavior of both base objects and derived objects change. They all sport the new behavior. When you want to change the behavior of derived objects and keep the original behavior of base objects, mark your derived members with hide. The base members are hidden from the derived members (with the same name, of course). We have covered how to use the hide modifier in Column 110.

Every class inherits from a base class. This statement is true because all classes are implicitly derived from the Object class. The following definition of class Foo:

class Foo {/* members should go here */}

is identical to this alternate definition:

class Goo extends Object {/* members should go here */}

The Object class includes three properties and five methods. These are the properties:

  • constructor
  • prototype
  • prototypeIsEnumerable

And these are the methods:

  • isPrototypeOf()
  • hasOwnProperty()
  • toLocaleString
  • toString
  • valueOf

So, every class supports these 8 members by default. You don't have to do anything specific to inherit them. When defining a new class, you can accept these members, override them, or hide them.

Next: How to use derived objects with base methods

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


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: June 3, 2002
Revised: June 3, 2002

URL: http://www.webreference.com/js/column111/2.html