Revision: 7288
Author: [email protected]
Date: Wed Dec  9 12:01:12 2009
Log: Updating the NullsUndefined wiki page to specify using == instead of  
=== when it is safe and makes the code shorter.
http://code.google.com/p/google-web-toolkit/source/detail?r=7288

Modified:
  /wiki/NullIsUndefined.wiki

=======================================
--- /wiki/NullIsUndefined.wiki  Fri Apr 18 09:14:03 2008
+++ /wiki/NullIsUndefined.wiki  Wed Dec  9 12:01:12 2009
@@ -35,18 +35,17 @@

  The net result of these cases is that the Java object identity operator  
cannot always be mapped into one !JavaScript operator.

-The matrix below describes the required comparison operators in each case.  
In all cases where the values are known to be non-`null`, we can continue  
to use the === operator as before. In some other cases, it is only  
necessary to switch to the == operator (because `undefined == null`).
-
-There are two special cases, dubbed (1) and (2) below, where extra code  
will need to be generated.
+The matrix below describes the required comparison operators in each case.  
We use `==` when possible, because it's the shortest option.  However, `==`  
cannot be used to compare a string to an object other than a string,  
because !JavaScript will convert the non-string to a string and compare  
those.  In such cases, `===` is used, and then it is necessary to  
canonicalize each side of the comparison to replace undefined by null.   
That way, if one side is undefined and the other null, after  
canonicalization they will both be null and thus `===`.
+

  ||      ||        ||        || !null  ||        ||        || ?null | 
|       ||      ||
  ||      ||        ||Object  || String || Widget || Object || String||  
Widget|| null ||
  ||      || Object || ===    ||        ||        ||        ||       | 
|       ||      ||
-||!null || String || ===    || ===    ||        ||        ||       | 
|       ||      ||
-||      || Widget || ===    || false  || ===    ||        ||       | 
|       ||      ||
+||!null || String || ===    || ==     ||        ||        ||       | 
|       ||      ||
+||      || Widget || ===    || false  || ==     ||        ||       | 
|       ||      ||
  ||      || Object || ===    || ===    || ===    || (1)    ||       | 
|       ||      ||
-||?null || String || ===    || ===    || false  || (1)    ||   ==  | 
|       ||      ||
-||      || Widget || ===    || false  || ===    || (1)    ||   (2) ||  
==    ||      ||
+||?null || String || ===    || ==     || false  || (1)    ||   ==  | 
|       ||      ||
+||      || Widget || ===    || false  || ==     || (1)    ||   (2) ||  
==    ||      ||
  ||      || null   || false  || false  || false  || ==     ||   ==  ||  
==    || true ||

  {{{

-- 
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to