> class B { > a() { > this.b(); > } > b() { > print('B.b'); > } > } > > class C extends B { > a() { > super.a(); > } > b() { > print('C.b'); > } > } > > var c = new C; > c.a(); // Should print 'C.b' > > With a dynamic super the above would lookup b in the wrong object > (B.prototype instead of C.prototype).
Note that with dynamic super, "this" never changes during the following method invocations, only "here" changes. c.a() => this = c, here = C.prototype (where a() was found) super.a() => this = c, here = B.prototype. Explanation for "here": a() was found by searching the prototype chain, starting at the prototype of the previous "here". Thus, the search starts at B.prototype where a property "a" is found. this.b() => this = c. The search for b() starts at "this" = c and finds a property "b" in the prototype of c (which is C.prototype). So it should work. It’s actually closer to the intuitive meaning of "super.a": - Perform the invocation as if it was this.a (meaning that the value of "this" is unchanged). - But: start the search for "a" in the prototype of the object where the current method "lives" (the "here" variable mentioned above). super.a(arg1, arg2) => Object.getPrototypeOf(here).a.call(this, arg1, arg2) -- Dr. Axel Rauschmayer a...@rauschma.de twitter.com/rauschma home: rauschma.de blog: 2ality.com _______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss