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
F A Q #2316
Comments
This is a great start. Thanks @Nami-Doc. edit: You could mention a CS equivalent to PHP's do (staticVar = initialValue) ->
(args...) -> # this function now has "static"-like access to `staticVar` Put that anywhere you would put the inner function. We have created a [closure](http://en.wikipedia.org/wiki/Closure_(computer_science\)). edit again: Your "this comment" link has an |
Thanks @michaelficarra ! I edited my post. |
closing since it's now a wiki page (I probably need to link it somewhere, tho) |
Hello guys.
Just went on the irc channel to ask something, which I think has been answered numerous time.
Jashkenas offered to set up a FAQ if there's good questions in it, so I'd like to ask you to come with the questions you had, that now looks obvious to you after it has been explained, and which surely has been explained a loot of time.
I'd like to start with :
Why does CoffeeScript requires "foo" to be defined when doing
foo ?= value
orfoo ||= value
Otherwise, it'd create a global, which is not what we want (if that is what you want, use,
window.foo ?= value
)If you're declaring the variable at the current scope, you know it doesn't exist - Javascript has no mecanic like php's static keyword.
Note that it perfectly works when used with classes :
If you want an alternative to PHP's
static
keyword, you can use a closure :Why is CoffeeScript sometimes using ["bar"] notation over .bar ?
CoffeeScript detects reserved keywords (as the auto-quoting of keywords in array notation) and prefer to use the array-access syntax ([]), because in ES3, reserved keywords (
throw
,class
, ...) reserved words were not allowed as the right operand in a member access. See this comment or more informationWhy is the existantial "?" operator only checking
this.foo != null
, shouldn't it also check fortypeof === 'undefined'
?X == null
tests that either X is null or undefined, assuming it is in scope. If we can't make that assumption, we need to do atypeof
test to avoidReferenceError
s. See the Abstract Equality Comparaison Algorithm (section 11.9.3) for more informations (especially steps 2 and 3)(see #1869, #1631)
(I'd like to thank @jashkenas for the first one, and @michaelficarra for his infinite patience for the two others).
The text was updated successfully, but these errors were encountered: