Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#1319 closed defect (wontfix)

this.inherited can cause undesired repeat calls to the same function

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


Create a superclass with a function foo() that calls this.inherited() Create a subclass. Call and the function foo() is called twice.


dojo.declare('my.classes.root', null, {

tester: function() {




dojo.declare('my.classes.branch', my.classes.root, {

tester: function() {

dojo.debug('branch'); this.inherited('tester', arguments);



dojo.declare('my.classes.leaf', my.classes.branch, { });

var leaf = new my.classes.leaf(); leaf.tester();

Gives: DEBUG: branch DEBUG: branch DEBUG: root

The tester() function at the 'branch' level should only be called once.

Attachments (1)

test_inherited.html (1003 bytes) - added by morris 15 years ago.
Run this in testslang to demonstrate issue.

Download all attachments as: .zip

Change History (3)

Changed 15 years ago by morris

Attachment: test_inherited.html added

Run this in testslang to demonstrate issue.

comment:1 Changed 15 years ago by sjmiles

Resolution: wontfix
Status: newclosed

This is again due to a misunderstanding of inherited. I will have to bring the inherited problem to the dev list because it is causing problems.

Inherited was a zero-weight solution in the sense that it did not involve attaching any additional data to the class or method ahead of time (that wasn't already there as a result of dojo.inherits). It's useful for invoking certain inheritance chains, but the limitations are not intuitive.

In particular, when you call leaf.tester() the context is my.classes.leaf. There is no information that indicates this method is actually coming from the superclass. So the inherited call, begins looking up the inheritance tree from my.classes.leaf finding the first ancestral version of tester' in my.classes.branch prototype, which it invokes (again).

It's certainly possible to improve inherits, but in general this is problematic, since most of the core devs (including me) are not sanguine about forcing JS into a classical OOP model.

comment:2 Changed 15 years ago by (none)

Milestone: 0.4

Milestone 0.4 deleted

Note: See TracTickets for help on using tickets.