Small corrections...
Example:
function SuperClass() {
}
function SubClass() {
}
SubClass.prototype = Object.create(SuperClass.prototype);
SubClass.prototype.foo = function() {
super.foo();
};
Behind the scenes:
- SubClass.prototype.foo.[[Super]] = Object.getPrototypeOf(SubClass.prototype);
- foo is desugared to:
SubClass.prototype.foo = function thisFunction() { // named function
expression
thisFunction.[[Super]].foo.call(this);
};
The “behind the scenes” work would be performed for object literals with a
proto operator and for class literals.
On Oct 1, 2011, at 17:51 , John J Barton wrote:
>
>
> On Sat, Oct 1, 2011 at 8:22 AM, Brendan Eich <[email protected]> wrote:
> > On Oct 1, 2011, at 4:23 PM, Lasse Reichstein wrote:
> >
> > On Sat, Oct 1, 2011 at 2:16 PM, Axel Rauschmayer <[email protected]> wrote:
> >>
> >> Then a super-call is always about letting "this" stay the same, but
> >> finding a "later" method: If your method lives in O1, you start your search
> >> for the super-property *after* O1 etc. In code this looks as follows:
> >> here.__proto__.foo.call(this, …)
> >> where "here" means "the object that the current method lives in". The
> >> effect is then:
> >> - here.__proto__: start your search *after* the method’s object and look
> >> for "foo".
> >> - .call(this, …): but keep "this" the same.
> >
> > Am I right that super-calls only works for class methods, because they know
> > the, statically determinable, prototype chain of its instances, and
> > therefore it knows where to start the search.
> > A normal method, e.g.,
> > var o = {__proto__: { m: function(x) { alert(x); }};
> > o.m = function(v) { super(v); }; // doesn't work
> >
> > You'd write super.m(v) there.
> > See http://wiki.ecmascript.org/doku.php?id=harmony:object_initialiser_super
>
> The idea sounds interesting but unfortunately reference is written in a
> language I don't understand.
> How about this case:
>
> var widget = {
> hookup: function() {
> // |this| is widget
> // |super| is widget
> window.addEventListener('load', function(event) {
> // |this| is NOT widget
> // |super| ??
> }, false);
> }
> };
> widget.hookup();
>
> jjb
>
>
> > /be
> >
> > o.m("hello");
> > won't be able to use "super", because it doesn't know where to start the
> > search - all it knows is the this-argument to the call and the function
> > itself, which doesn't necessarily mean anything.
> > /L
> > _______________________________________________
> > es-discuss mailing list
> > [email protected]
> > https://mail.mozilla.org/listinfo/es-discuss
> >
> >
> > _______________________________________________
> > es-discuss mailing list
> > [email protected]
> > https://mail.mozilla.org/listinfo/es-discuss
> >
> >
>
--
Dr. Axel Rauschmayer
[email protected]
twitter.com/rauschma
home: rauschma.de
blog: 2ality.com
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss