I want to add a method (not a property) to Array.prototype, but I dont want it to be enumerable and mess all for(...in...) in third party libraries.
//... Example:
//... Only push the value if it is not false
Array.prototype.pushValue = function(value){
if(value){ this.push(value); }
}
var pieces = [];
pieces.pushValue(0);
pieces.pushValue(1);
pieces.pushValue(2);
pieces.pushValue(null);
console.log(pieces.join(",")); //outputs 1,2
for(var k in pieces){
console.log(k); //outputs 0,1 and pushValue
}
I know I can use "hasOwnProperty" on my code to detect my custom methods, but I cannot change all code from third party libraries to add this verification.
Regardless if it's a good practice or not to add a method to Array.prototype, is it possible to add it as non enumerable?