Opened 10 years ago

Closed 9 years ago

Last modified 9 years ago

#10709 closed defect (fixed)

dojo.extend doesn not extend properly constructors produced by dojo.declare

Reported by: Jacco Compier Owned by: Eugene Lazutkin
Priority: high Milestone: 1.5
Component: Core Version: 1.4.0
Keywords: C3 Multiple inheritance extend Cc:
Blocked By: Blocking:

Description

The new C3 method resolution has some bugs in it. When a class is declared using multiple inheritance, only the first class is fully included in the declared class. Extended properties are not included!

An example is included below to make things clearer. abc.B2 and abc.C2 return "undefined" but should return a value.

I've looked at the source code and it seems that dojo.extend doesn't add properties to the _meta.hidden object of the class. Other methods like safeMixin and _mixin have the same problem.


Example:

dojo.declare ( 'test.a', null, { A1:'A1' } );
dojo.declare ( 'test.b', null, { B1:'B1' } );
dojo.declare ( 'test.c', null, { C1:'C1' } );

dojo.extend ( test.a, { A2: 'A2' } );
dojo.extend ( test.b, { B2: 'B2' } );
dojo.extend ( test.c, { C2: 'C2' } );

dojo.declare ( 'test.abc', [test.a,test.b,test.c], { } );
var abc = new test.abc();
alert(abc.A1+' - '+abc.B1+' - '+abc.C1+' - '+abc.A2+' - '+abc.B2+' - '+abc.C2);

Attachments (1)

jacco_declare.html (891 bytes) - added by Eugene Lazutkin 9 years ago.
Jacco's example.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 10 years ago by bill

Owner: changed from anonymous to Eugene Lazutkin

Not sure if this is supposed to be supported or not, there might be an extend method in classes created by dojo.declare() that you need to call. Anyway, assigning to Eugene.

comment:2 Changed 9 years ago by Eugene Lazutkin

Milestone: tbd1.5
Priority: highnormal
Status: newassigned

comment:3 Changed 9 years ago by Eugene Lazutkin

Related to #10788.

comment:4 Changed 9 years ago by Eugene Lazutkin

Summary: C3 Multiple inheritance doesn't work correctly when extending classesdojo.extend doesn not extend properly constructors produced by dojo.declare

dojo.extend() doesn't know about dojo.declare() intentionally.

dojo.declare() provides another mechanism to extend classes --- Class.extend(), which is defined on every class.

Rewriting your example:

dojo.declare ( 'test.a', null, { A1:'A1' } );
dojo.declare ( 'test.b', null, { B1:'B1' } );
dojo.declare ( 'test.c', null, { C1:'C1' } );

test.a.extend( { A2: 'A2' } );
test.b.extend( { B2: 'B2' } );
test.c.extend( { C2: 'C2' } );

dojo.declare ( 'test.abc', [test.a,test.b,test.c], { } );
var abc = new test.abc();
alert(abc.A1+' - '+abc.B1+' - '+abc.C1+' - '+abc.A2+' - '+abc.B2+' - '+abc.C2);

Changed 9 years ago by Eugene Lazutkin

Attachment: jacco_declare.html added

Jacco's example.

comment:5 Changed 9 years ago by Eugene Lazutkin

Resolution: fixed
Status: assignedclosed

(In [21793]) Using own properties instead of a shadow, !strict, fixes #10709, fixes #10788.

comment:6 Changed 9 years ago by Eugene Lazutkin

I corrected the bug and explained the behavior in http://docs.dojocampus.org/dojo/declare

Note: See TracTickets for help on using tickets.