Login Register

suggestion for dojo.xhr* functions

I had an issue which I posted here:
http://dojotoolkit.org/forum/dojo-core-dojo-0-9/dojo-core-support/callin...

I propose to have the dojo.xhr* family automatically include the 'this' object as a parameter in the new 'this' that is created in the handler functions.

It could be either passed in as a parameter in the function, e.g.

function_handler : function(response, ioArgs, original_this) { ... }

This way the old code still works if people just ignore the new original_this parameter, but you can have a slightly less ugly way of accessing your original 'this'.

Another possibility is to do what I did in the above mentioned post and access the old this as a member of the new this, as in:

function_handler : function(response, ioArgs) {
  this.original_this;
}

But preferably without having to explicitly pass original_this through the dojo.xhr call (I'm lazy).
I think this also preserves old code.

What do you all think? Any feedback?

using dojo.hitch, you can do

using dojo.hitch, you can do that and more very easily.

dojo.declare(....., {
     url:"foo.php",
     sender: function(){
           dojo.xhrGet({
                 url: this.url, load:dojo.hitch(this,"handler")
            });
     },

     handler: function(data, io){
         console.log(data)this.sender();
     }

});

got it

Thanks!

I have some code to rewrite... :-)