Context: tc39/proposal-set-methods#50
Proposed spec texts
Set.prototype.difference(arg), minimalist
- If Type(this) is not Object, or this does not have a [[SetData]] internal slot, throw a new TypeError exception.
- If Type(arg) is not Object, or arg does not have a [[SetData]] internal slot, throw a new TypeError exception.
- Let diffList be a List containing all elements that are in this.[[SetData]] but are not in arg.[[SetData]], using SameValueZero to determine identity. (Optional: formalize this with a loop that operates on the Lists.)
- Let newSet be ? OrdinaryCreateFromConstructor(%Set%, "%SetPrototype%", « [[SetData]] »).
- Set newSet.[[SetData]] to diffList.
- Return newSet.
If we wanted to accept iterables as arguments, then we would do the following:
Set.prototype.difference(arg), supports iterables
- If Type(this) is not Object, or this does not have a [[SetData]] internal slot, throw a new TypeError exception.
- Let argList be the empty list.
- If arg is not undefined or null, then set argList to ? IterableToList(arg).
- Let diffList be a List containing all elements that are in this.[[SetData]] but are not in argList, using SameValueZero to determine identity. (Optional: formalize this with a loop that operates on the Lists.)
- Let newSet be ? OrdinaryCreateFromConstructor(%Set%, "%SetPrototype%", « [[SetData]] »).
- Set newSet.[[SetData]] to diffList.
- Return newSet.