Ticket #1080 (closed defect: wontfix)

Opened 2 years ago

Last modified 18 months ago

Calling this.inherited skips intermediate methods

Reported by: guest Owned by: sjmiles
Priority: highest Milestone:
Component: Core Version: 0.3
Severity: major Keywords:
Cc:

Description

Run this code: dojo.lang.declare('MyObject?1', null, {

method1 : function () {

alert('I`m in MyObject?1');

}, method2 : function () { }

});

dojo.lang.declare('MyObject?2', MyObject?1, {

method1 : function () {

alert('Im in MyObject2 and Im not called!');

}, method2 : function () {

this.method1();

}

});

dojo.lang.declare('MyObject?3', MyObject?2, {

method1 : function () {

alert('I`m in MyObject?3'); this.inherited('method1');

}, method2 : function () {

this.inherited('method2');

}

});

new MyObject?3().method2();

I`m expecting three messages are shown, but only two or them really are here: "Im in MyObject3" and "Im in MyObject?1". What happen to "Im in MyObject2 and Im not called!"?

Thanks, Alexander

Attachments

Tests.html (1.1 kB) - added by guest 2 years ago.
Test file for the issue

Change History

Changed 2 years ago by guest

Test file for the issue

Changed 2 years ago by guest

Not fixed in trunk - have downloaded it and run the Test.html (attached)

Changed 2 years ago by dylan

  • owner changed from anonymous to sjmiles
  • milestone set to 0.4

Changed 2 years ago by sjmiles

  • status changed from new to closed
  • resolution set to wontfix

'inherited' does not do what you hope. In particular, you have to be careful when calling other methods from an inherited invocation.

The system is designed to allow you to chain a series of methods from an inheritance tree:

superSuperClass.method = function() { alert('hooray') };
superClass.method = function() { this.inherited("method") };
class.method = function() { this.inherited("method") };

To do that it keeps track of an 'inheritance context' which will foul you up if you start trying to call other methods that also use 'inherited'.

In particular, when MyObject?3.method1 calls inherited, the 'inheritance context' refers to MyObject?2, so the inherited method obtained is from MyObject?1.

To avoid problems, use prototypes directly, like so:

MyObject3.method1 = function () {
  alert('I`m in MyObject3'); 
  myObject2.prototype.method1.call(this);
}

Changed 18 months ago by anonymous

  • milestone deleted

Milestone 0.4 deleted

Note: See TracTickets for help on using tickets.