-
Notifications
You must be signed in to change notification settings - Fork 11
Passing arguments to the function #9
Comments
I'm not sure if the complexity is warranted; I think generally the performance of wrapping in an arrow function is pretty much the same as not. Worth thinking about tho! |
For reference, here's the PR in AMP. Frequently, it's just a single param that's needed, though sometimes I need to capture |
When programming in functional style I rarely encounter nullary functions (without arguments). So at first I'd agree for the need to have arguments (and don't care about On the other hand, if // for brevity just unary functions
var compose = f => g => x => f(g(x));
var h = compose(f, compose(Promise.resolve.bind(Promise), g)); // defining the function pipeline
h(x); // executing later
var h = compose(f, Promise.try.bind(Promise, g, x)) // defining the function pipeline
h(); // no way to specify the arguments at runtime Maybe I am wrong, but in this light I don't find |
When you need to do that, you can use an arrow. But when you don't, you avoid creating a closure just to forward arguments. I don't see any downside really to forward |
@syg what about a receiver/ |
My preference is to just not have support for forwarding the receiver. I feel like you can take a |
Given that the stated use case is "someone gives you a function to call", I don't think there's a need to support providing a |
I agree, it’s just that supporting arguments raises that question imo. Do we accept arguments to pass, modulo thisArg, anywhere else in the language that takes a callback? |
spec-wise, none - I put up #16 as a draft to discuss, which is a trivial change. |
This is less "taking a callback" and more "wrapping a callback". Most places that take a function do so because they're expecting a specific format of function to serve a specific role - like the So the closest analogies are |
That's a decently persuasive answer to the question, thanks. |
|
When linting for the old pattern in the AMP codebase, I'm frequently finding that the call expressions take parameters:
To requires a lot of either binding, or wrapping the function in an arrow closure. Would it be more performant for implementations to take these parameters in the call to
Promise.try
?The text was updated successfully, but these errors were encountered: