coolaj86/node-file-api — Issue #4: In FormData.js adding Array.prototype.forEachAsync is causing all sorts of issues.
Author: celer
Created: 2012-03-08 17:47:15+00:00
State: open

Hi,

So we're trying to use AHR2 and have been having persistent issues with attaching files, apparently when FromData is evaluated an additional function is added to Array, which then causes all sorts of havok all over our app, as the newly added function to Array shows up when iterating over any array.

i.e.

//NodeJS 6.12
Array.prototype.forEachAsync=function(){}
var myArray=[];
for(var i in myArray){ console.log(i); }
// returns forEachAsync

But this function is only added when we're attaching files.

Meaning our only choice is to now perform a typeof check in each for loop in our app :(

Possible fixes:

Use defineProperty/w enumerable=false
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/defineProperty

Or to simply change the scope of the function as it appears you only use it a few times, i.e. Array.forEachAsync(array...)

Thanks,

celer.