penguin/AstroJS

Javascript framework for my blog

commit 7624d2b2fbdaa25f339826cc5bd5889bddb3f484

author斟酌 鵬兄 <tgckpg@gmail.com>
date2017-03-07T10:31:07Z
subjectAvoid using for..in
commit 7624d2b2fbdaa25f339826cc5bd5889bddb3f484
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2017-03-07T10:31:07Z

    Avoid using for..in
---
 botanjs/src/Components/Vim/Actions/BUFFERS.js |  4 +++-
 botanjs/src/Components/Vim/Cursor.js          |  3 ++-
 botanjs/src/Components/Vim/VimArea.js         | 11 ++++++++---
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/botanjs/src/Components/Vim/Actions/BUFFERS.js b/botanjs/src/Components/Vim/Actions/BUFFERS.js
index 9248877..19ec446 100644
--- a/botanjs/src/Components/Vim/Actions/BUFFERS.js
+++ b/botanjs/src/Components/Vim/Actions/BUFFERS.js
@@ -48,10 +48,12 @@
 
 		var msg = ":buffers";
 
-		for( var i in Insts )
+		var l = Insts.length;
+		for( var i = 0; i < l; i ++ )
 		{
 			/** @type {Components.Vim.VimArea} */
 			var inst = Insts[ i ];
+			if( !inst ) continue;
 
 			var b = inst.index + " ";
 			var icur = inst.contentFeeder.cursor;
diff --git a/botanjs/src/Components/Vim/Cursor.js b/botanjs/src/Components/Vim/Cursor.js
index 25e858c..0e87891 100644
--- a/botanjs/src/Components/Vim/Cursor.js
+++ b/botanjs/src/Components/Vim/Cursor.js
@@ -598,7 +598,8 @@
 			// because phantomSpace is not a valid character
 			// So we calculate along with the phantomSpace here
 			var phantomSpace = X;
-			for( var i in lines )
+			var lc = lines.length;
+			for( var i = 0; i < lc; i ++ )
 			{
 				/** @type {Components.Vim.LineBuffer} */
 				var vline = lines[ i ];
diff --git a/botanjs/src/Components/Vim/VimArea.js b/botanjs/src/Components/Vim/VimArea.js
index aad55ee..27e5874 100644
--- a/botanjs/src/Components/Vim/VimArea.js
+++ b/botanjs/src/Components/Vim/VimArea.js
@@ -58,10 +58,10 @@
 			throw new Error( "This element is not compatible for VimArea" );
 		}
 
-		for( var i in Insts )
+		for( var i = 0; i < InstIndex; i ++ )
 		{
 			var inst = Insts[ i ];
-			if( inst.stage.element == element )
+			if( inst && inst.stage.element == element )
 			{
 				debug.Info( "Instance exists" );
 				return inst;
@@ -387,7 +387,12 @@
 
 	__readOnly( VimArea, "Instances", function() {
 		var clone = [];
-		for( var i in Insts ) clone.push( Insts[ i ] );
+
+		for( var i = 0; i < InstIndex; i ++ )
+		{
+			if( Insts[ i ] ) clone.push( Insts[ i ] );
+		}
+
 		return clone;
 	} );