Opened 13 years ago

Closed 12 years ago

#1453 closed defect (invalid)

this.inherited() fails when inherited method calls method in original class

Reported by: guest Owned by: sjmiles
Priority: high Milestone: 0.9
Component: Core Version: 0.3
Keywords: Cc:
Blocked By: Blocking:

Description

Consider the following:

dojo.declare( 'Foo', null, {
 func1: function () {
   alert( "Foo::func1" );
   this.func2();
 }
 ,func2: function () {
   alert( "Foo::func2" );
 }
});

dojo.declare( 'Bar', Foo, {
 func1: function () {
   alert( "Bar::func1" );
   this.inherited( 'func1' );
 }
 ,func2: function () {
   alert( "Bar::func2" );
   this.inherited( 'func2' );
 }
});

var bar = new Bar();
bar.func1();

I would expect to see:{{{ Bar::func1 Foo::func1 Bar::func2 Foo::func2 }}} Instead, I only see:{{{ Bar::func1 Foo::func1 Bar::func2 }}} I've checked this bug against trunk and it's still there.

The reason for this is that _inherited() sets this.___proto to the current context. This works so long as you're always going back in the tree. However, when you come back to where you started with the this.func2() call, this.___proto is incorrect. When this.inherited( 'func2' ) is called, it's starting the ancestral method search in Foo, not Bar.

The following HTML file demonstrates the problem:

<html>
  <head>
    <title>Test</title>
    <script src="dojo.js"></script>
    <script>
dojo.require( 'dojo.lang.declare' );
dojo.declare( 'Foo', null, {
  func1: function () {
    alert( "Foo::func1" );
    this.func2();
  }
 ,func2: function () {
    alert( "Foo::func2" );
  }
});

dojo.declare( 'Bar', Foo, {
  func1: function () {
    alert( "Bar::func1" );
    this.inherited( 'func1' );
  }
 ,func2: function () {
    alert( "Bar::func2" );
    this.inherited( 'func2' );
  }
});

var bar = new Bar();
bar.func1();
    </script>
  </head>
  <body><h2>Hello</h2></body>
</html>

Change History (3)

comment:1 Changed 13 years ago by dylan

Component: GeneralCore
Milestone: 0.5

comment:2 Changed 12 years ago by Adam Peller

Owner: changed from anonymous to sjmiles

sending this to the inherited() expert :)

comment:3 Changed 12 years ago by sjmiles

Resolution: invalid
Status: newclosed

This problem doesn't exist in 0.9.

Note: See TracTickets for help on using tickets.