spacer
Yehuda Shiran May 26, 2002
Handling Non-Qualified Name Collisions
Tips: May 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

When you import classes from outside your code, there is always a possibility of class and variable collisions, if you use non-qualified names. Non-qualified names sometimes do not uniquely identify a class or a class member, because these classes are defined in multiple namespaces. In such cases of ambiguity, the local class takes over the imported class. The following USA.Florida namespace defines the class Head, which includes the Governor function:

  package USA.Florida {
    public class Head {
      static var Governor : String = "Bush";
    }
  };
The following code defines a local class and a local function. They are named by the same names as above:

   class Head {
      static var Governor : String = "Davis";
   }
Now, we import USA.Florida, conflicting the definition of Head and Governor:

  import USA.Florida;
The class Head.Governor is non-qualified, because there is such a class in the USA.Florida namespace, and there is also a class by the same name in the local namespace. When you print the value of the non-qualified function Head.Governor, the local value will override the imported name. The code:

  print(Head.Governor);
will yield the following output:

  Davis
To learn more about JScript .NET, go to Column 109, JScript .NET, Part III: Classes and Namespaces.


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, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint