i like usetetris in my hads and motorbike games dirt bike games and somebmx gamesfrom the best Dirt Bike Games

Tutorials, extensions, and source files for ActionScript, Flash, and other Adobe products.

 

Equality (==) - Simple, Right?

Posted January 22, 2009 by senocular

I thought so too. But looking at the docs for the equality (==) operator showed something different. There are literally 15 different bullet points outlining the behavior of this thing! Granted, most of them are pretty obvious, but one I can say I think I would have gotten wrong on the test would be for NameSpace objects.
Apparently Namespace objects are equal simply if their URIs match - this regardless of their prefix values. What that means is:
var ns1:Namespace = new Namespace("foo", "uri");
var ns2:Namespace = new Namespace("bar", "uri");
namespace ns3 = "uri";

trace(ns1 == ns2); // true
trace(ns1 == ns3) // true

If you think about it, it makes sense, but to me, it's not very intuitive, especially when defined through the Namespace class.

Here's another shocker I don't think I've had the pleasure of running into before:
trace(new XMLList() == undefined); // true

Again, thinking about it, you'll want this to be true. But to look at the code above, it's not one's instincts to think it's correct.