utils.extend() destroys arrays
I'm currently implementing Criteo RTA. A part of the implementation is:
pbjs.bidderSettings = {
criteo: {
alwaysUseBid : true,
adserverTargeting: [{
key: "criteo",
val: function (bidResponse) {
return bidResponse.keys;
}
}
]
},
This should result in setTargeting(key, value) being called where 'value' is an array of zones which are present in the Criteo cookie.
Alas this doesn't work because: https://github.com/prebid/Prebid.js/blob/master/src/utils.js#L99
replaces the array with an Object. I fixed this by replacing this code with simply:
exports.extend = function(target, source){
target = target || {};
this._each(source,function(value,prop){
target[prop] = source[prop];
});
return target;
};
This also brings it more into accordance with Object.assign() where only one level of properties is copied.
@mkendall07 @jdelhommeau mind take a look?
maybe to avoid any breaking changes/still fix the array issue we could just change line 103 from:
if (typeof source[prop] === objectType_object) {
to
if (this.isA(source[prop], 'Object')) {
@BartVB would that work for criteo?
@nickjacob @BartVB @mkendall07 does this work? Is it preferable to copy arrays as arrays or is the object Object cast a requirement of the current implementation?
And does this solve this issue?
@protonate You'll need to search the source for callers of the function to determine how it's used today. I'm not sure if it will work right if it is changed.
I believe this is no longer needed, if any updates please reopen. Closing.
Apologies for the late response! Got sidetracked.
I've tested this with current master and that code still destroys arrays: https://github.com/prebid/Prebid.js/blob/c14bd2e99081ce121bb638219911764f9edf42bc/src/utils.js#L108
The solution which @nickjacob suggests solves the problem for me.