The bind operator is proposed JavaScript syntax, commonly written ::, for extracting a method while binding its this receiver. It combines method extraction with behavior similar to Function#bind, call, and apply. section 5.6 section 1.1
Use either operator form according to where the receiver and method appear:
- Binary form, obj :: method, places the bound object before the method: Success.of(2)::map(x => x * 2). section 5.6
- Unary form, ::obj.method, extracts a method already associated with an object, such as ::console.log or ::incrementor.inc. section 5.6
- Both forms produce a bound function, avoiding explicit calls to Function#bind when callbacks or fluent transformations need a stable this value. section 5.6
Fluent transformations and callbacks
Success.of(2)::map(x => x * 2)::map(x => x ** 2) produces Success(16). For callback binding, [1, 2, 3].map(::incrementor.inc) produces [3, 4, 5], replacing incrementor.inc.bind(incrementor). section 5.6
Reactive method extraction
ReactiveExtensions exposes methods such as skip, filter, map, and reduce. Observable.of(1, 2, 3, 4) :: skip(1) :: filter(isEven) :: map(square) :: reduce(add, 0) builds a stream pipeline while controlling each method's this reference. section 9.4.6
Success.of(2)::map(x => x * 2); // Success(4)
See the minimal binary-form example for binding map to a Success value. section 5.6
