Vousk-prod. Posted September 12, 2016 Share Posted September 12, 2016 Hi everybody, I noticed there are numerous places in the source where for (var i in arr) is used to iterate through arrays, which is a bad habits because when a thirdparty library is modifying Array prototype (which is also a bad habits, but it happens often) that will lead to bad iteration (since it will enumerates also prototype extensions added). Since BJS is written in TS, couldn't we just translate every for (var i in arr) { ... arr ... } to for (var elem of arr) { ... elem ... } ? adam 1 Quote Link to comment Share on other sites More sharing options...
Temechon Posted September 12, 2016 Share Posted September 12, 2016 It could create a lot of side effects, because for....of is iterating on values, whereas for...in is iterating on keys. In some cases it can work, but in others... adam 1 Quote Link to comment Share on other sites More sharing options...
Vousk-prod. Posted September 12, 2016 Author Share Posted September 12, 2016 Yep, but the several usages I noticed in the source are iterating through array to access values with arr[key] and never use directly the keys, so I think it would be ok. Quote Link to comment Share on other sites More sharing options...
Vousk-prod. Posted September 13, 2016 Author Share Posted September 13, 2016 Those iterations are called on arrays created by .split function, so I'm pretty sure it could be changed, but we can also use forEach or hasOwnProperties to fix the cases. I'll probably send a PR when I'll have some time. Pryme8 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 13, 2016 Share Posted September 13, 2016 Let's check the PR and see if this works Quote Link to comment Share on other sites More sharing options...
Vousk-prod. Posted October 10, 2016 Author Share Posted October 10, 2016 Oww, you changed your avatar DK, I'll miss the kosh Well, PR is on his way. GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.