| |
 | Posted by J C Calvarese in reply to Robert M. Münch | Permalink Reply |
|
J C Calvarese 
Posted in reply to Robert M. Münch
| Robert M. Münch wrote:
> Hi, I just found out (by pure chance) that there exists an !== operator, which seems to be for comparing objects or so. I couldn't find any documentation about this operator. Using != to compare objects bombs the kernel... Would be nice if this operator is added to the documentation.
When I first read you message, I though you were asking how these operators work. Now, I think I misunderstood the nature of your request, but I've included some information that might be helpful if someone wants to see an example regarding this issue.
[Comparing Objects]
I included an example that demonstrates some valid syntaxes for comparing objects. The recent addition of the "is" operator may explain any lack of mention of the older "===" operator. It's important to remember that these operators compare *references*, so that even if the values of the object properties are identical, false is returned as long as the references are different.
void main()
{
Object o, p;
/* o and p are instantiated as separate (different) objects. */
o = new Object();
p = new Object();
if(o is p) printf("o and p are references to the same object.\n");
else printf("o and p are different objects.\n");
if(!(o is p)) printf("They're not the same.\n");
else printf("Yes, o is the same reference as p!\n");
if(o === p) printf("o and p are references to the same object.\n");
else printf("o and p are different objects.\n");
if(!(o === p)) printf("They're not the same.\n");
else printf("Yes, o is the same reference as p!\n");
if(o !== p) printf("They're not the same.\n");
else printf("Yes, o is the same reference as p!\n");
printf("\nNow I'm gong to make them the same...\n");
delete p;
o = p; /* Now they're the same. */
if(o is p) printf("o and p are references to the same object.\n");
else printf("o and p are different objects.\n");
if(!(o is p)) printf("They're not the same.\n");
else printf("Yes, o is the same referenceas p!\n");
if(o === p) printf("o and p are references to the same object.\n");
else printf("o and p are different objects.\n");
if(!(o === p)) printf("They're not the same.\n");
else printf("Yes, o is the same reference as p!\n");
if(o !== p) printf("They're not the same.\n");
else printf("Yes, o is the same reference as p!\n");
}
--
Justin
http://jcc_7.tripod.com/d/
|