-
Notifications
You must be signed in to change notification settings - Fork 177
Bring CoffeeScript idiom to conditional statement. #89
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
Bring CoffeeScript idiom to conditional statement. #89
Conversation
An advantage of CoffeeScript compared to JavaScript is its ability to check for array membership with the `in` keyword. A feature it borrowed from Python.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good change. Can you put the array in a semantically-meaningful variable? For example
successResultCodes = [200, 304]
if req.status in successResultsCodesThen it reads even more naturally. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea.
I just commited this change.
Julien
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)
On Thursday, September 5, 2013 at 9:17 PM, James Holder wrote:
In chapters/ajax/ajax_request_without_jquery.md (http://ajax_request_without_jquery.md):
@@ -47,7 +47,7 @@ loadDataFromServer = -> > > req.addEventListener 'readystatechange', -> > if req.readyState is 4 # ReadyState Compelte > - if req.status is 200 or req.status is 304 # Success result codes > + if req.status in [200, 304] # Success result codes
Good change. Can you put the array in a semantically-meaningful variable? For example
successResultCodes = [200, 304] if req.status in successResultsCodesThen it reads even more naturally. :)
—
Reply to this email directly or view it on GitHub (https://github.com/coffeescript-cookbook/coffeescript-cookbook.github.com/pull/89/files#r6180754).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad to help!
On Thu, Sep 5, 2013 at 9:33 AM, nepsilon notifications@github.com wrote:
In chapters/ajax/ajax_request_without_jquery.md:
@@ -47,7 +47,7 @@ loadDataFromServer = ->
req.addEventListener 'readystatechange', ->
if req.readyState is 4 # ReadyState Compelte
if req.status is 200 or req.status is 304 # Success result codesif req.status in [200, 304] # Success result codesGood idea. I just commited this change.
… <#140ee54a1c0a3a35_>
-- Julien Sent with Sparrow (http://www.sparrowmailapp.com/?sig)
On Thursday, September 5, 2013 at 9:17 PM, James Holder wrote: In
chapters/ajax/ajax_request_without_jquery.md (
http://ajax_request_without_jquery.md): > @@ -47,7 +47,7 @@
loadDataFromServer = -> > > req.addEventListener 'readystatechange', -> >
if req.readyState is 4 # ReadyState Compelte > - if req.status is 200 or
req.status is 304 # Success result codes > + if req.status in [200, 304] #
Success result codes Good change. Can you put the array in a
semantically-meaningful variable? For example successResultCodes = [200,
304] if req.status in successResultsCodes Then it reads even more
naturally. :) — Reply to this email directly or view it on GitHub (
https://github.com/coffeescript-cookbook/coffeescript-cookbook.github.com/pull/89/files#r6180754).—
Reply to this email directly or view it on GitHubhttps://github.com//pull/89/files#r6181142
.
|
I like this. Anyone object to a |
|
Looks good to me :)
|
Bring CoffeeScript idiom to conditional statement.
An advantage of CoffeeScript compared to JavaScript is its ability to
check for array membership with the
inkeyword.A feature it borrowed from Python.
I thought it could be a good idea to use it whenever possible, as it draws a clear difference between the 2 languages, showcasing a convenient CoffeeScript feature.