Making "super" work outside a literal?

Peter Michaux petermichaux at gmail.com
Sun Jun 19 10:44:58 PDT 2011


On Sun, Jun 19, 2011 at 10:20 AM, Axel Rauschmayer <axel at rauschma.de> wrote:
> It would be nice if "super" could work in any method and not just those methods that are defined inside an object literal. Then, a method would have to know what object it resides in, e.g. via an implicit parameter.

So you want "super" to be dynamic but tied to the value of "this"
inside that function? Something like...

function fn() {
    return this.alpha + super.beta();
}

function Foo() {}
Foo.prototype.alpha = function() {return 1;};
Foo.prototype.beta = function() {return 2;};

function Bar() {}
Bar.prototype = Object.create(Foo.prototype);
Bar.prototype.beta = function() {return 5;};

var b = new Bar();
fn.call(b); // 1 + 2 = 3

Peter


More information about the es-discuss mailing list