Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Array.prototype.peek/removeAt/remove shouldn't be enumerable #57

Closed
jnordstrom1983 opened this issue Jun 13, 2016 · 1 comment
Closed

Comments

@jnordstrom1983
Copy link

The added functions to the array object shouldn't be enumerable as they may break other plugins that enumerates all properties in an array.

Steps to reproduce the issue:

var tempArray = [1,2,3];
for(var i in tempArray){
   console.log(tempArray[i])
}

Expected result:
[Log] 1 [Log] 2 [Log] 3

Result:

[Log] 1
[Log] 2
[Log] 3
[Log] function () {
    ...
}
[Log] function (index) {
   ...
}
[Log] function (item) {
   ...
}

Fix:
I've added this to my app to resolve this issue.

if(Array.prototype.peek){
  Object.defineProperty(Array.prototype, "peek", { 
    enumerable  : false
  });
}

if(Array.prototype.removeAt){
  Object.defineProperty(Array.prototype, "removeAt", { 
    enumerable  : false
  });
}

if(Array.prototype.remove){
  Object.defineProperty(Array.prototype, "remove", { 
    enumerable  : false
  });
}
@adnathan
Copy link
Contributor

Thank you so much for the report! I've just committed the fix.

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

No branches or pull requests

2 participants