Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#4770 closed defect (invalid)

Can't override Dictionary.add(key, value)

Reported by: guest Owned by: Tom Trenka
Priority: high Milestone:
Component: Dojox Version: 0.9
Keywords: Cc: ole.ersoy@…
Blocked By: Blocking:

Description

Hi,

I've created a test class like this:

dojo.provide("dojo.Test");

dojo.require("dojox.collections.Dictionary");

dojo.declare( "dojo.Test",

dojox.collections.Dictionary,

{

add: function(thekey, thevalue) {

alert(thekey);

}

});

Import as follows:

dojo.require("dojo.Test");

Create a new instance and invoke Test.add() like this:

var test = new dojo.Test(); test.add("key", "value");

The alert never gets triggered. Thoughts?

Ole

Change History (3)

comment:1 Changed 12 years ago by Adam Peller

Component: GeneralDojox
Owner: changed from anonymous to Tom Trenka

comment:2 Changed 12 years ago by Tom Trenka

Resolution: invalid
Status: newclosed

It's very possible that the reason for this is because the entire Collections set is based on closures and private functions, as opposed to using a mixin object on the prototype. This is because of the desire to keep internal lists private and away from the developer, and was by design.

Because of this, you're seeing an unintended effect where your override is really being impressed on the prototype of your new object, which doesn't have any access to the internal method or variable definitions.

So then this is actually by design...so I'm going to close the ticket. If you'd like help designing a similar class for your own use, hit the forums under DojoX (http://dojotoolkit.org/forum/) and I'll help you out there, since I'm sure others will be interested as well.

comment:3 Changed 12 years ago by guest

Why close the ticket though? Why not just leave this open until it gets fixed? We could create a DictionaryWrapper? with an add method that can be overridden and that delegates to Dictionary.add(). This takes 2 seconds, and solves it, but it's silly.

Also, I think people submitting bugs / improvements would be a lot more encouraged if things like this were handled dead on. Why close an improvement suggestion, when it's a valid improvement? Anyone coding in OO would expect to be able to override Dictionary.add(). Leaving this closed is just setting it up for a repeat.

I'll help fix Dictionary. I'll leave the ticket closed out of respect, but I strongly feel it should be open.

Note: See TracTickets for help on using tickets.