tc39 / proposal-bind-operator

This-Binding Syntax for ECMAScript
1.74k stars 30 forks source link

Consider & over :: #23

Closed rymohr closed 9 years ago

rymohr commented 9 years ago

Just to throw out another syntax option since I'm not sold on :: either (https://github.com/zenparsing/es-function-bind/issues/10).

// reads naturally when chaining / cascading
getPlayers()
  &map(x => x.character())
  &takeWhile(x => x.strength > 100)
  &forEach(x => console.log(x))

document.querySelectorAll("div.myClass")
  &find("p")
  &html("hahaha")

// conceptually similar(ish) to address-of operator
Promise.resolve(123).then(&console.log)
$(".some-link").on("click", &view.reset)

Technically foo&bar is a valid variable name (foo::bar is not) but I haven't seen variables like that in the wild.

sebmck commented 9 years ago

& cannot be used as it's already used by the bitwise and operator.

rymohr commented 9 years ago

Doh. For some reason I thought spaces were required for that one.