tc39 / js-outreach-groups

62 stars 7 forks source link

Review requests for MDN docs for TC39 proposals #9

Open littledan opened 5 years ago

littledan commented 5 years ago

MDN is a wiki, so writing articles there can feel like sending it to a black hole.

In this thread, let's post links to our recently posted MDN articles or edits about TC39-related topics, so that others can see them and comment on them.

Use a :+1: GitHub react if you read something and it looks good, or @-mention the poster of the request to give review comments.

It's not clear whether a GitHub thread will work or something smaller like email threads would be better; let's not hesitate to switch to something else if this doesn't work out.

cc @sarahgp @shwetank @romulocintra @bkardell @chicoxyzzy @neilkakkar @vaidehijoshi @pipobscure

bendtherules commented 4 years ago

This issue looks empty, so let me start with something šŸ˜€.

In Array.prototype.concat mdn page, it does not talk about ArraySpeciesCreate behavior. ArraySpeciesCreate uses the same constructor as "this" to create the output array.

That is, if "this" is actually created from a subclass of Array - then what will be the type of the returned array. Say, Array1 extends Array and then we do (new Array1()).concat([1]) - then is output instanceof Array1?

Should we add this information to that page? Or is that more of a Implementation detail? I guess this behavior is also applicable for some other Array methods, not just concat.

ljharb commented 4 years ago

It might be being removed soon, so thatā€™s probably best not to document for now.

bendtherules commented 4 years ago

It might be being removed soon

So, what is likely to get removed? Constructor reuse and @@species? It will then return a plain array?

Also, one more nitpick from the description -

TheĀ concatĀ method creates a new array consisting of the elements in the object on which it is called, followed in order by, for each argument, the elements of that argument (if the argument is an array) or the argument itself (if the argument is not an array). It does not recurse into nested array arguments.

Is it clear enough from the text that - both "this" and other arguments will be treated in this way (either spreaded or appended as whole) ?
To me, it reads like this behavior is only applicable for arguments.

ljharb commented 4 years ago

Yes.

ā€œthe elements in the object in which it is calledā€ is the receiver (the this), and then each argument is processed as described.

bendtherules commented 4 years ago

But then, what happens if the receiver itself is not spreadable? Like Array.prototype.concat.call({a:1} , array2);

From what i understand - the whole list of (receiver + all arguments) is treated in the same way - spread or append, not just the arguments. But mdn doc says, this applies for only arguments.

Which understanding is wrong?

ljharb commented 4 years ago

The same thing if an argument is not spreadable. Theyā€™re all treated the same, but MDN isnā€™t going into detail about the obscure edge case of using .call on a non-array.