Skip to content

Instantly share code, notes, and snippets.

@getify
Last active August 29, 2015 13:58
Show Gist options
  • Save getify/9936912 to your computer and use it in GitHub Desktop.
Save getify/9936912 to your computer and use it in GitHub Desktop.
super re-binding?
class P {
foo() { console.log( "P 'foo'" ); }
}
class C extends P {
foo() {
super();
}
}
var c1 = new C();
c1.foo(); // "P 'foo'"
var D = {
foo: function() { console.log( "D 'foo'" ); }
};
var E = {
foo: C.prototype.foo.toMethod( E, "foo" )
};
// Link E to D for delegation
Object.setPrototypeOf( E, D );
E.foo(); // D 'foo'
@getify
Copy link
Author

getify commented Apr 2, 2014

toMethod(..) takes a new [[HomeObject]] as first parameter, and optionally a new name for the method. super is derived as [[HomeObject]].[[Prototype]].

http://people.mozilla.org/~jorendorff/es6-draft.html#sec-function.prototype.tomethod

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment