Opened 15 years ago
Closed 14 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 15 years ago by
Component: | General → Core |
---|---|
Milestone: | → 0.5 |
comment:2 Changed 14 years ago by
Owner: | changed from anonymous to sjmiles |
---|
comment:3 Changed 14 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
This problem doesn't exist in 0.9.
sending this to the inherited() expert :)