samuelgoto / proposal-block-params

A syntactical simplification in JS to enable DSLs
204 stars 8 forks source link

Prototype methods that accept a callback #18

Open rwaldron opened 6 years ago

rwaldron commented 6 years ago

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?

samuelgoto commented 6 years ago

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 notifications@github.com 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 !

rwaldron commented 6 years ago

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.

samuelgoto commented 6 years ago

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?