Allen Wirfs-Brock (2013-12-03T17:15:13.000Z)
domenic at domenicdenicola.com (2013-12-10T01:30:59.565Z)
On Dec 2, 2013, at 7:51 PM, Andrea Giammarchi wrote: > Reading this: http://esdiscuss.org/topic/november-19-2013-meeting-notes#content-6 > > I was wondering if anyone would be so kind to provide a concrete/real-world use case for toMethod() since I am having hard time to imagine a scenario where a super can be so easily invoked, being (AFAIK) multiple inheritance not allowed right now in ES6 specs. toMethod is a low level primitive that can be used to implement things like Object.mixin in a manner that works correctly with functions that reference super. > > When exactly would a piece of code invoke a super withou knowing which one is it? Anytime you want to before/after/around wrap a call to the the method that would otherwise be invoked. Anytime you want to define a "mixin" on an object with a known interface but multiple implementations. > Wouldn't this lead to potential infinite loop within the super invocation itself if referenced from a subclass that was already using toMethod() within the super() itself? There is a potential for a super invocation-based unbounded recursion loops, but it doesn't require the use to toMethod to make it occur. consider ```js class P { } class C extends P { foo() { console.log("f"); super(); } } P.prototype.foo=C.prototype.foo; (new C).foo(); //infinite recursion outputting lines of f's ``` If instead you coded: ```js P.prototype.foo = C.prototype.foo.toMethod(P.prototype); ``` you would not get the infinite recursion, instead you would get two f's followed by a "method not found" .