proposal-block-params icon indicating copy to clipboard operation
proposal-block-params copied to clipboard

Prototype methods that accept a callback

Open rwaldron opened this issue 8 years ago • 3 comments

I didn't see any examples of this, so I'm curious:

let numbers = [1, 2, 3];
let mapped =  numbers.map {
  // ...
}

Does this work? How would I get the value, index, object args?

rwaldron avatar Nov 09 '17 19:11 rwaldron

This wouldn't work in the current formulation, as it is limited to functions (as opposed to methods). Do you think this use case is important enough that you think we should care?

WRT parameters, this is the current formulation:

https://github.com/samuelgoto/proposal-block-params#bindings

Which granted would be a bit awkward in this case.

On Thu, Nov 9, 2017 at 11:17 AM, Rick Waldron [email protected] wrote:

I didn't see any examples of this, so I'm curious:

let numbers = [1, 2, 3];let mapped = numbers.map { // ... }

Does this work? How would I get the value, index, object args?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/samuelgoto/proposal-block-params/issues/18, or mute the thread https://github.com/notifications/unsubscribe-auth/AAqV6oo14hFVRgTeSzCRSiRMVH0v1cYGks5s00-9gaJpZM4QYgLs .

-- f u cn rd ths u cn b a gd prgmr !

samuelgoto avatar Nov 09 '17 19:11 samuelgoto

https://github.com/samuelgoto/proposal-block-params#bindings

Hopefully any suggestions that include special properties of a this object are off limits until https://github.com/samuelgoto/proposal-block-params/issues/16 is resolved.

rwaldron avatar Nov 09 '17 19:11 rwaldron

To be clear, this is as close as it would get in the current formulation (without any assumptions made on the this reference).

let numbers = [1, 2, 3];
let mapped =  map(numbers) do (value, index) {
  // ...
  console.log(`${value} ${index}`);
}

Does that sound reasonable?

samuelgoto avatar Nov 27 '17 19:11 samuelgoto