Skip to content

Instantly share code, notes, and snippets.

@arv
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arv/c0658b074a7d706ccf33 to your computer and use it in GitHub Desktop.
Save arv/c0658b074a7d706ccf33 to your computer and use it in GitHub Desktop.
@@new and @@create
class B {
  constructor(x) {
    this.x = x;
  }
  static [Symbol.create]() {
    var o = super();
    weakMap.set(o, 123456789);  // Dom wrapper foo
    return o;
  }
}

function C(x) {
  B.call(this, x);
}
C.__proto__ = B;
C.prototype = {
  __proto__: B.prototype,
  constructor: C
};

or

class B {
  constructor(x) {
    this.x = x;
  }
  static [Symbol.new](x) {
    var o = super();
    weakMap.set(o, 123456789);  // Dom wrapper foo
    this.call(o, x);
    return o;
  }
}

But this is just @@create in sheep's clothing...

class B {
  constructor(x) {
    this.x = x;
  }
  static [Symbol.create]() {
    var o = super();
    weakMap.set(o, 123456789);  // Dom wrapper foo
    return o;
  }
  static [Symbol.new](x) {
    var o = this[Symbol.create]();
    this.call(o, x);
    return o;
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment