mavo icon indicating copy to clipboard operation
mavo copied to clipboard

Property names that clash with array methods produce unexpected results

Open DmitrySharabin opened this issue 7 years ago • 4 comments

Hi @LeaVerou,

I am not sure exactly whether it's a bug or not, but in my testcase if doesn't work as it should in the mv-action attribute inside collections. Will you please have a look at my example here?

DmitrySharabin avatar Mar 02 '19 23:03 DmitrySharabin

Actually, it looks like it's a bug with the name "shift": it collides with the special property $shift about whether the Shift key was pressed, even though the property should have priority. If I change it to "shift2" then it seems to work. Could you please confirm so I can edit the bug accordingly? (Btw I'm travelling and will be back on Wednesday, so that's the earliest I can properly look into it)

LeaVerou avatar Mar 03 '19 09:03 LeaVerou

Shame on me. I didn't even think about it. 😢 Yep, I changed the name of the property, and everything worked as it should.

Thanks, Lea! Have a nice journey! 😃

DmitrySharabin avatar Mar 03 '19 10:03 DmitrySharabin

Actually it's a different clash: shift seems to clash with the array shift() method! We had a similar problem with our filter() function clashing with the Array#filter() method, but the way we solved it was specific to functions, which is why it's not helping here...

LeaVerou avatar Mar 08 '19 22:03 LeaVerou

Reduced testcase: https://codepen.io/leaverou/pen/pXxxvO?&editors=1100#0

Interestingly, the bug only happens when there is an actual property with that name, otherwise it (correctly) just prints "unshift".

LeaVerou avatar Jul 08 '19 07:07 LeaVerou