micktaiwan/meteor-vermongo

for (... in ...) {} modified when mickaelfm:vermongo is installed (meteor 1.2.x).

Closed this issue · 4 comments

Hi Mickael,

I have an issue using vermongo (with meteor 1.2.x, I don't verify with older meteor release).

WIthout vermongo (1.1.3) in my project, if I use for (... in ...) {} , I got (on client or server side) :

l = [ 1 , 2 ]
[1, 2]
for ( x in l ) { console.log( x ) }
0
1

With vermongo (1.1.3) installed in my project, I got :

l = [ 1 , 2 ]
[1, 2]
for ( x in l ) { console.log( x ) }
0
1
diff
equals

Others packages using for (... in ...) {} are broken.

I'm not sure to understand but I think this issue should by linked to #2.

Thanks for your help.

Have a nice day.

Philippe

What is the resuklt of your loop ? It seems that your are listing the array methods. Right ? diff and equals are methods added to Array prototype in the Vermongo package.

Hi Mickael,

that's right, diff and equals are listed in "for ... in ..." loop. But, I think this should not occurs.

This is perhaps due to ecmascript 6's compatibility from meteor 1.2.

Some libraries using "for ... in ..." loop are broken if they use vermongo. For example : JackAdams/meteor-accounts-ldap#8

If the problem is with the ecmascript 6's compatibility from meteor 1.2, a fix may come with the next version of meteor...

Have a nice day.

Philippe

A solution to add methods to Array.prototype that are not enumerable in "for ... in ..." loop exists (from ecmascript 5.1, incompatibility may exist with older browsers).

http://stackoverflow.com/questions/13296340/how-to-define-method-in-javascript-on-array-prototype-and-object-prototype-so-th

Object.defineProperty(Array.prototype, "find", {
    enumerable: false,
    writable: true,
    value: function(testFun) {
        // code to find element in array
    }
});

Using this solution increases vermongo's compatibility with other libraries.

Have a nice day.

Philippe

I have made the 2 functions local