This project is archived and is in readonly mode.

#121 ✓invalid
Aaron Newton

Class.Extend broken reference to parent?

Reported by Aaron Newton | June 12th, 2008 @ 11:54 PM | in 2.0 (closed)

Consider the following example:

Request.HTMLX = new Class({
  Extends: Request.HTML,
  send: function(options){
    (function(){
       this.parent(options);
    }).delay(1000, this);
  }
});
new Request.HTMLX({url: '/some/file.html'}).send();

You'll get this error:

arguments.callee.caller.parent has no properties
[at line:  return arguments.callee.caller.parent.apply(this, arguments); ]

If you do this:

Request.HTMLX = new Class({
  Extends: Request.HTML,
  send: function(options){
     this.parent(options);
  }
});
new Request.HTMLX({url: '/some/file.html'}).send();

It works just fine.

Comments and changes to this ticket

  • w00fz

    w00fz June 13th, 2008 @ 01:34 AM

    • State changed from “new” to “invalid”

    this.parent can be used inside class methods only.

  • Aaron Newton

    Aaron Newton June 13th, 2008 @ 02:14 AM

    It IS inside a class method. send is a class method of Request.HTML, and this is bound to the instance.

  • w00fz

    w00fz June 13th, 2008 @ 04:51 AM

    When you have this.parent inside a function, that function become the caller, even if this is bound to the instance. You can still use this.parentOf, tho.

  • Aaron Newton

    Aaron Newton June 13th, 2008 @ 06:33 AM

    That doesn't make any sense. By this logic, you can never reference this.parent() inside any inner function. That means you can't reference it inside of iterations (.each), $try, chain, bound methods. The class I'm having trouble with (http://clientside.cnet.com/docs/...) is something that I've been using for months now, first as part of Mootools 1.11 and then 1.2b and right up until the final release. Something changed here. It's ridiculous to think that you can't reference this.parent inside an inner function - that's what javascript (and Mootools) is full of!

    This bug is NOT invalid.

  • digitarald

    digitarald June 13th, 2008 @ 07:29 AM

    You create a new function, a new reference without this.parent! Closures are not class methods! Also, you delay it, parent is only available when the class method is called. Imagine the result of a persistent parent method. It is indeed possible in each loops, we should add specs for that.

    Try that instead of your closure:

    this.parent.delay(1000, this, $A(arguments));

  • Aaron Newton

    Aaron Newton June 13th, 2008 @ 08:36 PM

    Ok. After discussing with digitarald I get it - parent references are removed after the method is called. I will point out that this is a very recent change - 1.2b and 1.11 didn't have this limitation.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

Tags

Pages