#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('I
m in MyObject2 and I
m 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 "I
m in MyObject1". What happen to "Im in MyObject2 and I
m not called!"?
Thanks, Alexander
Attachments (1)
Change History (5)
Changed 15 years ago by
Attachment: | Tests.html added |
---|
comment:1 Changed 15 years ago by
Not fixed in trunk - have downloaded it and run the Test.html (attached)
comment:2 Changed 15 years ago by
Milestone: | → 0.4 |
---|---|
Owner: | changed from anonymous to sjmiles |
comment:3 Changed 14 years ago by
Resolution: | → wontfix |
---|---|
Status: | new → closed |
'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); }
Test file for the issue