My code was not a fix, it was intended to show that while your first case’ 
behavior was explained in the spec (super had to be null), the one of my own 
case was not (ie: the interaction of ‘super’ with bind).

I’ve no idea of how we should solve the problem. Maybe the ‘bind’ method should 
create a copy of the original function whose ‘boundThis’ is equal to the 
object’s this and whose ‘super’ is equal to Object.getPrototypeOf(this).

  function Obj() { }
  Obj.prototype.getX = function() { return 10; }

  function Obj2() { Obj(this); }
  Obj2.prototype = Object.create(Obj.prototype);
  Obj2.prototype.getX = function() { return super.getX()+1; }

  var a = new Obj2();
  var b = Object.create({getX:function() { return 100; }}); 
  b.getX=a.getX.bind(b);

  assert(a.getX() == 11);
  assert(a.getX() == 101); // or should it be 11?
A typical programming language would (probably) require 11, but then you’ve no 
way to solve the asynchronous pattern (super would remain null and only this 
would be bound).

François

From: John J Barton 
Sent: Saturday, October 01, 2011 6:16 PM
To: François REMY 
Cc: Brendan Eich ; Axel Rauschmayer ; es-discuss 
Subject: Re: Super-calls



On Sat, Oct 1, 2011 at 9:05 AM, François REMY <fremycompany_...@yahoo.fr> wrote:

  In my understanding, super would be null.

  What would be more complex is :
    var widget = {
        hookup: function() {
            // |this| is widget
            // |super| is widget
            window.addEventListener('load', function(event) {

                // |this| is widget
                // |super| ??
            }.bind(this), false);

Unfortunately my example and your fix are both impractical. We have to bind the 
function *and* save a reference to it because we don't have garbage collection. 
That provides another example to try to understand super:
            this.loadHandler = function(event){
               // this is widget
               // Now super?
               }.bind(this); 
            window.addEventListener('load', this.loadHandler, false);

        }
    };
    widget.hookup();
jjb
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to