Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterating over arrays with for ... in causes unexpected behavior in some scenarios #77

Closed
kumavis opened this issue Nov 4, 2013 · 5 comments

Comments

@kumavis
Copy link

kumavis commented Nov 4, 2013

Iterating over arrays with for ... in breaks if additional functionality is added to Array.prototype.

// some polyfill or extension lib adds additional functionality
Array.prototype.first = function(){ return this[0] }

// your code tries to iterate with the for loop, causing undesirable behavior 
for( x in [1,2] ){ console.log(x) }
// (keys)
//=> 0
//=> 1
//=> first   <-- problematic

// forEach (and map) still work as expected
[1,2].forEach(function(x) { console.log(x) })
// (values)
//=> 1
//=> 2
@kumavis
Copy link
Author

kumavis commented Nov 4, 2013

@3rd-Eden
Copy link
Member

3rd-Eden commented Nov 4, 2013

@kumavis
Copy link
Author

kumavis commented Nov 4, 2013

@3rd-Eden PR incomming shortly

@kumavis
Copy link
Author

kumavis commented Nov 4, 2013

@3rd-Eden you beat me to it ✌️

@3rd-Eden
Copy link
Member

3rd-Eden commented Nov 4, 2013

Fix released as 1.4.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants