Table of Contents

Examples

Native syntax for f.bind(self):

const hasOwnProperty = Object.prototype.hasOwnProperty;
function hasOwn(obj, key) {
    return obj::hasOwnProperty(key);
}

Calling a superclass constructor:

function MySubClass(x, y, z) {
    this::SuperClass(x);
    this.y = y;
    this.z = z;
}

Bound-method extraction:

var method = obj::obj.foo;

Bound-method extraction with implicit object:

var method = ::obj.foo;

Syntax

Roughly:

Expression ::= ...
            |  Expression "::" Expression

Precedence: should bind just barely weaker than “.”

TODO: grammar details

Semantics

Essentially, e1::e2 is equivalent to do { let obj=e1; e2.bind(obj) } with the original meaning of .bind (the let-binding ensures left-to-right evaluation).

And ::e uses the base of the reference, or null if the base is not an object.

Rationale

  • better usability for method extraction + this-binding
  • better usability for Function.prototype.call
  • don’t have to worry about .bind or .call being shadowed/mutated
  • addresses some super use cases without need for implicit lexical binding
  • static syntax means no dynamic tests (e.g. for mutation of .bind or .call) ⇒ better performance
  • important for code generators that don’t want to be penalized for generating .call

References

 
strawman/bind_operator.txt · Last modified: 2012/03/28 17:37 by dherman
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki