Last active
August 29, 2015 13:58
-
-
Save getify/9936912 to your computer and use it in GitHub Desktop.
super re-binding?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
toMethod(..)
takes a new[[HomeObject]]
as first parameter, and optionally a newname
for the method.super
is derived as[[HomeObject]].[[Prototype]]
.http://people.mozilla.org/~jorendorff/es6-draft.html#sec-function.prototype.tomethod