-
-
Notifications
You must be signed in to change notification settings - Fork 597
Closed

Description
I would be obliged if one explain AddUniqueOp.applyTo comment:
https://github.com/parse-community/Parse-SDK-JS/blob/master/src/ParseOp.js#L199
applyTo(value: mixed | Array<mixed>): Array<mixed> {
if (value == null) {
return this._value || [];
}
if (Array.isArray(value)) {
// copying value lets Flow guarantee the pointer isn't modified elsewhere
var valueCopy = value;
var toAdd = [];
this._value.forEach((v) => {
if (v instanceof ParseObject) {
if (!arrayContainsObject(valueCopy, v)) {
toAdd.push(v);
}
} else {
if (valueCopy.indexOf(v) < 0) {
toAdd.push(v);
}
}
})
return value.concat(toAdd);
}
throw new Error('Cannot add elements to a non-array value');
}
why we need valueCopy reference?
var valueCopy = value;
and why we need copy technique?
thanks
Metadata
Metadata
Assignees
Labels
No labels