You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by jm...@apache.org on 2017/06/01 05:58:15 UTC

[4/7] git commit: [flex-asjs] [refs/heads/develop] - use === and !== rather than == and !=

use === and !== rather than == and !=


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/ce22dc67
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/ce22dc67
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/ce22dc67

Branch: refs/heads/develop
Commit: ce22dc67a26579611d0454eddbeef53a7db5d5d6
Parents: ee3a98e
Author: Justin Mclean <jm...@apache.org>
Authored: Thu Jun 1 13:21:47 2017 +1000
Committer: Justin Mclean <jm...@apache.org>
Committed: Thu Jun 1 13:21:47 2017 +1000

----------------------------------------------------------------------
 .../flex/org/apache/flex/utils/StringUtil.as    | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/ce22dc67/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/StringUtil.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/StringUtil.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/StringUtil.as
index 8674180..f53ba62 100644
--- a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/StringUtil.as
+++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/StringUtil.as
@@ -84,12 +84,12 @@ package org.apache.flex.utils
 		 */
 		public static function substitute(str:String, ... rest):String
 		{
-			if (str == null) return '';
+			if (str === null) return '';
 			
 			// Replace all of the parameters in the msg string.
 			var len:uint = rest.length;
 			var args:Array;
-			if (len == 1 && rest[0] is Array)
+			if (len === 1 && rest[0] is Array)
 			{
 				args = rest[0] as Array;
 				len = args.length;
@@ -125,7 +125,7 @@ package org.apache.flex.utils
 		 */
 		public static function repeat(str:String, n:int):String
 		{
-			if (n == 0)
+			if (n === 0)
 				return "";
 			var a:Array = [];
 			for (var i:int = 0; i < n; i++)
@@ -158,11 +158,11 @@ package org.apache.flex.utils
 		public static function restrict(str:String, restrict:String):String
 		{
 			// A null 'restrict' string means all characters are allowed.
-			if (restrict == null)
+			if (restrict === null)
 				return str;
 			
 			// An empty 'restrict' string means no characters are allowed.
-			if (restrict == "")
+			if (restrict === "")
 				return "";
 			
 			// Otherwise, we need to test each character in 'str'
@@ -285,7 +285,7 @@ package org.apache.flex.utils
 			if (n > 0)
 			{
 				code = restrict.charCodeAt(0);
-				if (code == 94) // caret
+				if (code === 94) // caret
 					allowIt = true;
 			}
 			
@@ -296,11 +296,11 @@ package org.apache.flex.utils
 				var acceptCode:Boolean = false;
 				if (!inBackSlash)
 				{
-					if (code == 45) // hyphen
+					if (code === 45) // hyphen
 						inRange = true;
-					else if (code == 94) // caret
+					else if (code === 94) // caret
 						setFlag = !setFlag;
-					else if (code == 92) // backslash
+					else if (code === 92) // backslash
 						inBackSlash = true;
 					else
 						acceptCode = true;
@@ -322,7 +322,7 @@ package org.apache.flex.utils
 					}
 					else
 					{
-						if (charCode == code)
+						if (charCode === code)
 							allowIt = setFlag;
 						lastCode = code;
 					}


Re: [4/7] git commit: [flex-asjs] [refs/heads/develop] - use === and !== rather than == and !=

Posted by Alex Harui <ah...@adobe.com.INVALID>.
The same if() logic applies in ActionScript as well.

I've been caught by this one before:

If (“0”) is true

If (0) is false


-Alex

On 6/1/17, 12:44 AM, "piotrz" <pi...@gmail.com> wrote:

>Ahh So much love to JS :)
>
>
>
>-----
>Apache Flex PMC
>piotrzarzycki21@gmail.com
>--
>View this message in context:
>https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache-fle
>x-development.2333347.n4.nabble.com%2FRe-4-7-git-commit-flex-asjs-refs-hea
>ds-develop-use-and-rather-than-and-tp61973p61989.html&data=02%7C01%7C%7C22
>cfd0bede6a41d1933a08d4a8c42732%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%
>7C636319007813353831&sdata=y%2FSeXdup7oujotDJEs6mCgpHfAozVShYCb%2B8NbRz4cg
>%3D&reserved=0
>Sent from the Apache Flex Development mailing list archive at Nabble.com.


Re: [4/7] git commit: [flex-asjs] [refs/heads/develop] - use === and !== rather than == and !=

Posted by piotrz <pi...@gmail.com>.
Ahh So much love to JS :) 



-----
Apache Flex PMC
piotrzarzycki21@gmail.com
--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/Re-4-7-git-commit-flex-asjs-refs-heads-develop-use-and-rather-than-and-tp61973p61989.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: [4/7] git commit: [flex-asjs] [refs/heads/develop] - use === and !== rather than == and !=

Posted by Justin Mclean <ju...@classsoftware.com>.
HI,

> if(restrict) it's a good thing.

Not really a good thing in general as for instance:
if(“”) is false
if(“0”) is true
if(NaN) is false

> Thinking about what to do with null/undefined - It seems to be resolution -
> isn't it?

It casts a much wider net than just null and undefined.

> Maybe not exactly for the case, but in general?

It might be OK in this case as the empty string is treated like null but in general best to be avoided I think.

Thanks,
Justin

Re: [4/7] git commit: [flex-asjs] [refs/heads/develop] - use === and !== rather than == and !=

Posted by piotrz <pi...@gmail.com>.
If I correct understand your links making 

if(restrict) it's a good thing.

I don't understand this one "get messy fast" ? :) 

Thinking about what to do with null/undefined - It seems to be resolution -
isn't it? Maybe not exactly for the case, but in general?

Thoughts?

Piotr



-----
Apache Flex PMC
piotrzarzycki21@gmail.com
--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/Re-4-7-git-commit-flex-asjs-refs-heads-develop-use-and-rather-than-and-tp61973p61981.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: [4/7] git commit: [flex-asjs] [refs/heads/develop] - use === and !== rather than == and !=

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

> if (restrict) {}

Style best to be avoided IMO.

Lots of things are truthy / falsy in JS. [1] For instance empty string is false and so is NaN and it gets messy fast. [2]

Thanks,
Justin

1. https://developer.mozilla.org/en-US/docs/Glossary/Falsy
2. https://dorey.github.io/JavaScript-Equality-Table/

Re: [4/7] git commit: [flex-asjs] [refs/heads/develop] - use === and !== rather than == and !=

Posted by piotrz <pi...@gmail.com>.
Understand. :) I'm wondering whether all cases are not resolves something
like that:

if (restrict) {}

Just thinking loud, cause I'm fine with your changes here. 

Piotr



-----
Apache Flex PMC
piotrzarzycki21@gmail.com
--
View this message in context: http://apache-flex-development.2333347.n4.nabble.com/Re-4-7-git-commit-flex-asjs-refs-heads-develop-use-and-rather-than-and-tp61973p61976.html
Sent from the Apache Flex Development mailing list archive at Nabble.com.

Re: [4/7] git commit: [flex-asjs] [refs/heads/develop] - use === and !== rather than == and !=

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

> What will happen if "restrict" will be undefined ?

A null restrict according to the comment mean any characters means nothing is restricted same as an empty string and that make sense.

Undefined is well undefined :-) having an undefined restrict doesn’t really make any sense so I don’t know what the expected behaviour should be.

If you do pass in undefined in it will throw an exception, perhaps it should not do that but I’m not sure.

Thanks,
Justin

Re: [4/7] git commit: [flex-asjs] [refs/heads/develop] - use === and !== rather than == and !=

Posted by Piotr Zarzycki <pi...@gmail.com>.
Hi Justin,

What will happen if "restrict" will be undefined ?

Piotr

2017-06-01 7:58 GMT+02:00 <jm...@apache.org>:

> use === and !== rather than == and !=
>
>
> Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
> Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/ce22dc67
> Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/ce22dc67
> Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/ce22dc67
>
> Branch: refs/heads/develop
> Commit: ce22dc67a26579611d0454eddbeef53a7db5d5d6
> Parents: ee3a98e
> Author: Justin Mclean <jm...@apache.org>
> Authored: Thu Jun 1 13:21:47 2017 +1000
> Committer: Justin Mclean <jm...@apache.org>
> Committed: Thu Jun 1 13:21:47 2017 +1000
>
> ----------------------------------------------------------------------
>  .../flex/org/apache/flex/utils/StringUtil.as    | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/
> ce22dc67/frameworks/projects/Core/src/main/flex/org/apache/
> flex/utils/StringUtil.as
> ----------------------------------------------------------------------
> diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/StringUtil.as
> b/frameworks/projects/Core/src/main/flex/org/apache/flex/
> utils/StringUtil.as
> index 8674180..f53ba62 100644
> --- a/frameworks/projects/Core/src/main/flex/org/apache/flex/
> utils/StringUtil.as
> +++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/
> utils/StringUtil.as
> @@ -84,12 +84,12 @@ package org.apache.flex.utils
>                  */
>                 public static function substitute(str:String, ...
> rest):String
>                 {
> -                       if (str == null) return '';
> +                       if (str === null) return '';
>
>                         // Replace all of the parameters in the msg string.
>                         var len:uint = rest.length;
>                         var args:Array;
> -                       if (len == 1 && rest[0] is Array)
> +                       if (len === 1 && rest[0] is Array)
>                         {
>                                 args = rest[0] as Array;
>                                 len = args.length;
> @@ -125,7 +125,7 @@ package org.apache.flex.utils
>                  */
>                 public static function repeat(str:String, n:int):String
>                 {
> -                       if (n == 0)
> +                       if (n === 0)
>                                 return "";
>                         var a:Array = [];
>                         for (var i:int = 0; i < n; i++)
> @@ -158,11 +158,11 @@ package org.apache.flex.utils
>                 public static function restrict(str:String,
> restrict:String):String
>                 {
>                         // A null 'restrict' string means all characters
> are allowed.
> -                       if (restrict == null)
> +                       if (restrict === null)
>                                 return str;
>
>                         // An empty 'restrict' string means no characters
> are allowed.
> -                       if (restrict == "")
> +                       if (restrict === "")
>                                 return "";
>
>                         // Otherwise, we need to test each character in
> 'str'
> @@ -285,7 +285,7 @@ package org.apache.flex.utils
>                         if (n > 0)
>                         {
>                                 code = restrict.charCodeAt(0);
> -                               if (code == 94) // caret
> +                               if (code === 94) // caret
>                                         allowIt = true;
>                         }
>
> @@ -296,11 +296,11 @@ package org.apache.flex.utils
>                                 var acceptCode:Boolean = false;
>                                 if (!inBackSlash)
>                                 {
> -                                       if (code == 45) // hyphen
> +                                       if (code === 45) // hyphen
>                                                 inRange = true;
> -                                       else if (code == 94) // caret
> +                                       else if (code === 94) // caret
>                                                 setFlag = !setFlag;
> -                                       else if (code == 92) // backslash
> +                                       else if (code === 92) // backslash
>                                                 inBackSlash = true;
>                                         else
>                                                 acceptCode = true;
> @@ -322,7 +322,7 @@ package org.apache.flex.utils
>                                         }
>                                         else
>                                         {
> -                                               if (charCode == code)
> +                                               if (charCode === code)
>                                                         allowIt = setFlag;
>                                                 lastCode = code;
>                                         }
>
>