Follow

@nex3 @noelle how is what you are requesting different from `array.forEach(add.bind(other))`?

@nex3 @noelle i just wanted to make sure that was what you meant and not `array.forEach($ => $.add())`

there is currently a proposal for a :: operator which does binding (link: github.com/tc39/proposal-bind- ), but afaict it doesn't do property access (so you would still need other::other.add). it's also Stage 1 which means it is mostly exploratory and may never get added to the language.

i think in most real JS code, one should EITHER:

1) be calling a function from a prototype, e.g. `Set.prototype.add.bind(other)` (i would love a more convenient way of saying this), or

2) be calling bare functions, like `add.bind(other)`, possibly destructured like `const { add } = other`.

the cases where i actually state something like `other.add.bind(other)` are pretty small and usually can be avoided with good API design (`other.add(...array)` or `new Other (...other, ...array)`). not saying it never happens! but i don't think reducing that particular bit of wordiness is necessarily a high priority? in your example i’d probably honestly use a for...of loop because it’s much more readable.

Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.