-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docs: enhance documentation of existential operators #1631
Comments
++, this would be great. We just need to be sure that the section doesn't get too long on the page, and still feels bite-sized. Direct documentation patches can be committed to master, and cherry-picked over to gh-pages. |
Just from the viewpoint of a user, I recently tried to start using the existential operator but the docs didn't seem to correspond with what was actually happening and I ended up not using it, so +1 to this. |
That's true. The documentation states that the unary However, in my compilations, it leaves out undefined-checking, and simply becomes I'm using the Node.js executable method on Windows 7 64-bit, and |
Here we go again. This needs to be mentioned somewhere in the docs as well to avoid getting this question all the time. @TylerWayne: |
@michaelficarra: Your patience is infinite. I don't think that mentioning this in the docs is going to stop anyone from asking the question -- people just look at the generated output and open a ticket or comment immediately. |
My apologies; thank you very much for clarifying. Yes, it would be very good to get this in the docs for novice developers like myself. |
@jashkenas: I think it may actually help. @TylerWayne said that the main source of his confusion was not the compilation itself, but the disparity between what he saw and what was listed in the documentation. It probably won't help with cases where someone sees two different compilations in their own code, not realising that one usage is on an undeclared variable, but it may help with instances like @TylerWayne's. Maybe. At the very least, it will educate people about a good javascript practice. |
+1 on better documentation, even if nobody reads it. If nothing else, when the questions come up in the future, you can point folks at the docs. |
I understand @jaskenas' reasons for wanting to keep documentation byte-sized, clear and minimalist - it speaks to what CS is all about, and is a quick and clear intro. On the other hand it would be fantastic to have some more detailed documentation, and examples of common use etc. Perhaps the official documentation could link to a wiki page on each sub section? where we can flesh it out as a real reference rather than just a quick and powerful intro. |
Big +1 for this, particularly regarding the part that says
…which is very confusing to the less experienced among us. Maybe just a couple of sentences right after that paragraph? Something like:
And then maybe some code blocks showing that
compiles to
Incidentally, I'm in favor of a complete, authoritative reference to go along with the intro docs—but I think this particular declared/undeclared thing is confusing enough that it warrants at least some mention even in the concise version. |
But |
It checks if its value is undefined, which will result in a TypeError if the variable isn't declared. |
@Nami-Doc yes, I was just telling that the documentation addition suggested by @wmayner was not correct in fact However I noticed this exact behavior (the TypeError) while doing some tests, and now I understand why CoffeeScript compiles to (so if something should be added to the documentation, I think that would be that.) |
@ymeine Thanks for that correction; I didn't realize that. In that case, I'm with you—some mention of that behavior should be in the documentation, perhaps even just a footnote. |
* Docs: named functions and function declarations * No more prototypal `extends`; update docs and example * More comprehensive documentation of the existential operator; closes #1631 * Better document operators, including `from` * No fat arrow class methods anymore * Destructuring shouldn’t say that default values are applied in case of undefined or null * Spinoff generator and async functions into their own sections; reorder things so that the sections on functions come just before classes, and destructuring goes next to the operators (which discuss assignment) * Rewrite “CoffeeScript 2” section, making it less practical and more explanatory; move practical info into “Usage” * Update “Variable Scoping and Lexical Safety” section to remove incorrect reference to Ruby (fixes #2360), add missing details about the safety wrapper, add note about `let`/`const`. * Updated browser compiler * Updated docs * Rewrite Literate CoffeeScript breaking changes * Split apart the “Breaking Changes” and “Unsupported Features” sections into separate sidebar items and files * Add example of `not in`, closes #3281 * Fix words in bold that should be in backticks * Consolidate some breaking changes sections * Add Node API documentation; closes #3551 * Move the chaining documentation out of the changelog into its own section
Done in #4536. |
Right now, the documentation for our existential operators is either poor or non-existent. We should list all of the following operators along with proper definitions of their behaviour and possibly individual names (taken from #1613, the issue that inspired this one):
?
:a?
tests thata
is in scope anda != null
?
:a ? b
returnsa
ifa
is in scope anda != null
; otherwise,b
?.
and?[ ]
: soaked property access:a?.b
ora?['b']
returnsa.b
ifa
is in scope anda != null
; otherwise,undefined
?( )
: soaked function invocation:a?(b, c)
(ora? b, c
) returns the result of callinga
(with argumentsb
andc
) ifa
is in scope and callable; otherwise,undefined
?=
: existential assignment:a ?= b
assigns the value ofb
toa
ifa
is not in scope or ifa == null
; produces the new value ofa
Some particular parts of the current documentation that bother me:
The text was updated successfully, but these errors were encountered: