TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Partial Application and Lambda Parameter Syntax for JavaScript

52 pointsby skellertorover 7 years ago

7 comments

wwwighamover 7 years ago
If you really like the idea of syntactic partial application in your JavaScript, you should check out the stage 1 tc39 proposal for exactly that: <a href="https:&#x2F;&#x2F;github.com&#x2F;rbuckton&#x2F;proposal-partial-application" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rbuckton&#x2F;proposal-partial-application</a> It&#x27;s slowly being worked through the committee, so if you care enough about the feature, you should consider voicing your support.
评论 #16275297 未加载
a-salehover 7 years ago
Funny, I already kinda use partial application in Javascript, just by using curried functions a lot. I.e.<p>const add = x =&gt; y =&gt; x + y<p>This is definitely non-idiomatic, but the definition syntax itself doesn&#x27;t look that bad, if you can stomach writing add(1)(2) to use it.<p>I do agree that using _ would probably be a better solution :-)
评论 #16275215 未加载
评论 #16272365 未加载
rmrfrmrfover 7 years ago
&gt; In Kotlin specifically, this is a shorthand for anonymous functions where, if you don’t specify an argument, one will automatically exist with the name <i>it</i><p>I&#x27;m pretty sure Kotlin borrowed this idea from Groovy.
评论 #16275225 未加载
citycideover 7 years ago
Hi everyone, I&#x27;m the author. Looks like I&#x27;m a little late to the party (this post snuck by me) but I&#x27;ll try to answer any questions you might have.<p>I&#x27;d also like to point out the online playground [0] which allows you to use this directly in your browser and see what it compiles to.<p>[0]: <a href="https:&#x2F;&#x2F;citycide.github.io&#x2F;param.macro" rel="nofollow">https:&#x2F;&#x2F;citycide.github.io&#x2F;param.macro</a>
some1elseover 7 years ago
Nice article. I still prefer arrow functions over positional arguments though, because this approach trades some clarity for syntactic sugar. Until partial application becomes part of JavaScript, the import statement will probably outweigh the informative &quot;boilerplate&quot; it helps obscure anyway (there&#x27;s rarely more than one use case for partial application inside a well-factored component).
评论 #16273596 未加载
optimuspaulover 7 years ago
Doesn&#x27;t javascript have enough magic in it to make code difficult to follow? What is the benefit to adding more?
评论 #16275280 未加载
评论 #16275378 未加载
kalekoldover 7 years ago
Are babel plugins the new C preprocessor? and have all the problems associated with that.
评论 #16274532 未加载
评论 #16275960 未加载