microsoft / ace

Build Cordova apps with true native UI
http://microsoft.github.io/ace
Other
850 stars 157 forks source link

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

Closed jnordstrom1983 closed 7 years ago

jnordstrom1983 commented 7 years ago

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 commented 7 years ago

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