Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#1080 closed defect (wontfix)

Calling this.inherited skips intermediate methods

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

Description

Run this code: dojo.lang.declare('MyObject1', null, {

method1 : function () {

alert('I`m in MyObject1');

}, method2 : function () { }

});

dojo.lang.declare('MyObject2', MyObject1, {

method1 : function () {

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

}, method2 : function () {

this.method1();

}

});

dojo.lang.declare('MyObject3', MyObject2, {

method1 : function () {

alert('I`m in MyObject3'); this.inherited('method1');

}, method2 : function () {

this.inherited('method2');

}

});

new MyObject3().method2();

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

Thanks, Alexander

Attachments (1)

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

Download all attachments as: .zip

Change History (5)

Changed 13 years ago by guest

Attachment: Tests.html added

Test file for the issue

comment:1 Changed 13 years ago by guest

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

comment:2 Changed 13 years ago by dylan

Milestone: 0.4
Owner: changed from anonymous to sjmiles

comment:3 Changed 13 years ago by sjmiles

Resolution: wontfix
Status: newclosed

'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 MyObject3.method1 calls inherited, the 'inheritance context' refers to MyObject2, so the inherited method obtained is from MyObject1.

To avoid problems, use prototypes directly, like so:

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

comment:4 Changed 12 years ago by (none)

Milestone: 0.4

Milestone 0.4 deleted

Note: See TracTickets for help on using tickets.