4 ms·
This function f(some_param, callback) bla() return 1 f(10) |u,t| -> callback_code_here or f(10, success, failure) succss
by mratzloff 14y ago
This
function f(some_param, callback)
bla()
return 1
f(10) |u,t| ->
callback_code_here
or
f(10, success, failure)
succss: |data| ->
console.log("Success!", data)
failure: |error| ->
console.log("Error: ", error)
are not simpler than valid CoffeeScript, such as
f = (someParam, callback) ->
bla()
callback 1 # presumably your intent
f 10, (u, t) -> # callback code here
or
success = (data) -> console.log("Success!", data)
failure = (data) -> console.log("Error: ", error)
f 10, success, failure
- arnarbi 14y agoI agree, and I don't want to simplify CS, but rather JS. The thing that bothers me about CoffeeScript is the call syntax without parenthesis but with commas - which seems to me the main source of "surprises". The main benefit of it however is allowing you to write anonymous function arguments without chasing closing delimiters. I would like something that lies in between JS and CS, with that particular benefit but without the weird grammar.
- mratzloff 14y agoMy solution above (naming functions) is one solution to the problem. Wrapping ambiguous objects or arrays is another: f 1, 2, { foo: "bla" bar: "bla" }, (error, result) -> # do something with result For a series of function parameters, the leading comma is another: f.asyncMap (item) -> foo item , (error, result) -> # do something with result
- arnarbi 14y agof.asyncMap (item) -> foo item , (error, result) -> # do something with result The readability of that is terrible. I (and most people) can easily figure out how to make myself understood to the parser, that's not an issue at all. The itch that CS scratches is severe, but I believe there is an opportunity to have something much better in terms of readability and predictability.
- mratzloff 14y agoWhich is why it was the third alternative, and not the first. :-)