Opened 11 years ago

Closed 7 years ago

#7827 closed enhancement (wontfix)

support this.inherited for [DontEnum] methods

Reported by: Mike Wilson Owned by: sjmiles
Priority: high Milestone: future
Component: Core Version: 1.2beta
Keywords: Cc:
Blocked By: Blocking:

Description

Using dojo.declare in class hierarchies together with this.inherited() to call superclass methods can lead to surprises when overriding native Object methods:

dojo.declare("A", null, {
	toString: function() {
		return "A";
	}
});
dojo.declare("B", A, {
	toString: function() {
		return this.inherited(arguments) + ":B";
	}
});

The example above will not work in current Dojo 1.2 and will lead to the following exception:

B: inherited method "undefined" mismatch

To get it to work you need to explicitly name the method in the inherited call like so:

this.inherited("toString", arguments)

This is because the class's methods are prepared for this.inherited() in an enumeration scan of the available properties:

dojo.mixin(dojo.declare, {
	...
	_extend: function(props){
		...
		for(i in props){ if(dojo.isFunction(fn=props[i]) && !0[i]){fn.nom=i;fn.ctor=this;} }

Thus, toString() and other native/hidden methods on Object will not be prepared in this way and will have to use the explicit calling convention shown above. There's just like six methods on Object so these (or maybe just toString and valueOf) could be explicitly inspected to resolve this problem and support all method names:

for(i in props){ if(dojo.isFunction(fn=props[i]) && !0[i]){fn.nom=i;fn.ctor=this;} }
dojo.forEach(["toString","valueOf"], function(i) { 
	if(props.hasOwnProperty(i) && dojo.isFunction(fn=props[i]) && !0[i]){fn.nom=i;fn.ctor=this;}); 
}

Change History (4)

comment:1 Changed 11 years ago by Mike Wilson

Sorry, forgot to add [patch][cla] to the heading...

comment:2 Changed 11 years ago by Adam Peller

Owner: changed from anonymous to sjmiles

comment:3 Changed 10 years ago by dante

Milestone: tbdfuture

punting enhancement.

comment:4 Changed 7 years ago by bill

Resolution: wontfix
Status: newclosed

Since we will probably get rid of this.inherited() in 2.0, closing this as wontfix.

Note: See TracTickets for help on using tickets.