- 🇬🇧United Kingdom AndyF
Very specific situation, but I just had this occur. It looks like in my case it was because a dependency update caused an addition to
Array.prototype
which polluted the results ofshallowCopy
inremoveMapMarkers()
ingeolocation-api.js
. This is down to usingjquery.extend()
:properties inherited from the object's prototype will be copied over
That's in contrast to
Object.assign()
which might make more sense to use.To clarify what I'm saying open up dev tools on a page with jQuery loaded and run:
jQuery.extend({}, []); Array.prototype.customFn = () => 42; jQuery.extend({}, []); // The result of this second one won't be empty.
I've generally heard it's bad practice to modify a built-in prototype, but by the same token should we program defensively and use
Object.extend()
? (Which also means less jQuery, yay!) - Status changed to Needs review
8 months ago 10:00am 4 September 2024 - 🇬🇧United Kingdom AndyF
The suggestion in the last comment seemed to fix things for us. But coming back to it the next morning without an issue on production to fix, and actually I wonder why
jQuery.extend()
was ever being used... it seems to me it's just used to shallow clone an array, whereas I thoughtjQuery.extend()
was all about pulling properties from objects. (But it can work because array elements are properties of objects, but semantically it's not what we want I don't think.)I've updated it to just use normal array functions, I think it's a little easier to follow and is still resilient to modification of
Array.prototype
. Thanks! - Status changed to Fixed
8 months ago 2:59pm 4 September 2024 - 🇩🇪Germany christianadamski Berlin, Germany
Thanks!
Not an issue in v4 in general - no jQuery there.
Automatically closed - issue fixed for 2 weeks with no activity.