javascript - CoffeeScript curiousity about splat & this implementation -
javascript - CoffeeScript curiousity about splat & this implementation -
so, looking thru code functional & currying driver of it.. seeing convention of splat usage, , though can "see" doing in compiled javascript, have not seen mention of docs etc.. on "..." splat usage coffeescript @ end of line (see below).
for instance, have:
flip = (f) -> (as...) -> f as.reverse()...
which compiles to:
flip = function(f) { homecoming function() { var as; = 1 <= arguments.length ? __slice.call(arguments, 0) : []; homecoming f.apply(null, as.reverse()); }; };
now, understand "as..." beingness used as:
as = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
taking arguments , assigning them "as".
but, not wrapping head around usage here:
-> f as.reverse()... # <-- "..." @ end.
if remove (the '...'), "apply" of compiled goes away.. so, convention here of using "..." @ end. missing concept in coffeescript knowledge.
there's nil special ...
beingness @ end of line.
what see here difference between splat parameter , splat argument. ...
operator used both cases because related. may confusing, though, since these uses inverses of each other.
as.reverse()...
splat argument passed f
. compiled javascript uses f.apply
break as.reverse()
multiple arguments receiver f
.
as...
splat parameter. compiled javascript uses __slice
convert arguments
object array within receiver, collect arguments single list.
javascript coffeescript
Comments
Post a Comment