knadh / localStorageDB

A simple database layer for localStorage and sessionStorage for creating structured data in the form of databases and tables
http://nadh.in/code/localstoragedb
814 stars 128 forks source link

Improper use of for..in #8

Closed ralstondasilva closed 12 years ago

ralstondasilva commented 12 years ago

Hi,

I was porting an existing Javascript program to Windows 8 (Metro). I came across an issue that I wanted to bring to your notice.

The localStorageDB code has a few places where a for.. in loop is used to iterate through arrays. The issues I was facing were fixed when I changed these to a regular for loop. I thought I could bring this to your notice so you could fix it in the code. The for..in loop is meant to loop through properties of an object. http://www.w3schools.com/js/js_loop_for_in.asp

Here are some references with explanations on why it shouldn't be used to loop through arrays: http://blog.sebarmeli.com/2010/12/06/best-way-to-loop-through-an-array-in-javascript/ http://stackoverflow.com/questions/3010840/loop-through-array-in-javascript

Thanks for sharing localStorageDB with all of us. Hope this helps make it better!

Ralston

knadh commented 12 years ago

You are right, blame my laziness! I'll commit a patch soon.

Kailash

knadh commented 12 years ago

ce0109a572c2034452aed5b1219e4a6a14c7e3d4 fixes this.

ralstondasilva commented 12 years ago

Thanks :)

Have a great day!

Ralston

On Tuesday, April 24, 2012, Kailash Nadh wrote:

ce0109a572c2034452aed5b1219e4a6a14c7e3d4 fixes this.


Reply to this email directly or view it on GitHub: https://github.com/knadh/localStorageDB/issues/8#issuecomment-5303365