-
Notifications
You must be signed in to change notification settings - Fork 23
Spec should not handle sparse arrays #8
Comments
Should holes be skipped? I think all array methods ES6+ have explicitly not skipped holes. There's a consistency argument to be made, though, that skip behavior of the "d" version should match the "non-d" version. |
This polyfill does not handle subclassing but seems it's just something for showing basic functionality. It could be fixed just by replacing spread to |
@ljharb I'm for consistency. |
Consistency with ES6 and new array methods, or consistency with the non-d version of any given d method? |
With non-d, sure - it's non logically to add unnecessary inconsistency. |
There's inconsistency here regardless - it's inevitable. All we're doing is choosing which consistency/inconsistency we prefer. |
Those methods at first are versions of old methods so they should follow the old logic. |
I went by fidelity to the proposed spec which checks for property existence, and consistency with corresponding mutating array methods which do skip or otherwise respect holes. |
Even don't look to the consistency with non-d methods - I think that it's not a case of array iteration where ES6+ methods should not skip holes, it's the logic of complete shallow array cloning - the array should be the same as the original - with the same holes if they are presented - here no ES6+ equals - only old methods like |
So I agree holes should not be skipped, I will note that for the next spec draft. (please note that the spec is definitely a work in progress at stage 0) |
@rricard it will break consistency with non-d methods: [1,,,,2].reverse().forEach(console.log); // => 2, 1
[1,,,,2].reversed().forEach(console.log); // => 2, undefined, undefined, undefined, 1 |
Ok, I will add the question tag because it is not obvious which one to choose. |
After discussing in the R&T monthly call, we are deciding to break consistency with non-'ed methods and will convert holes to We are aware, this doesn't make the feature a drop-in replacement for We can discuss it further if you feel it should be discussed but please know we got a pretty strong signal against holes. This still needs to be properly reflected in the spec and will be as we work on fixing #7. |
seems resolved across spec and polyfill |
The polyfill uses the spread operator to clone which means that holes are not skipped like in the proposed spec.
The text was updated successfully, but these errors were encountered: