4 ms·
> This is really weird: getUser = (id) -> url = "users/#{id}" dfd = $.ajax url: url format: 'json' method: 'get' url: url p
by Cushman 15y ago
> This is really weird:
getUser = (id) ->
url = "users/#{id}"
dfd = $.ajax
url: url
format: 'json'
method: 'get'
url: url
promise: dfd.promise()
> It’s hard to recognize instantly that I’m actually
> calling $.ajax, not just assigning it. If you don’t know
> CoffeeScript, I’m sure the last two lines are totally
> baffling.
Um... I agree, but as someone who does know the language, that's clear, unambiguous and easy to read. I maybe wouldn't use implicit object return there, but it doesn't surprise me to see it.
In fact, I'll make a positive argument for the implicit call syntax: the whitespace under 'dfd' tells me, without reading any further, that the line is a call which takes an object argument. Without significant whitespace, I couldn't rule out it being just a typo.