What’s the right way to use the arguments property of a function?
This is how I’m currently using it, but I’m pretty sure I’m not using it correctly:
First, I define my parameters:
parameters = {};
parameters.ID = $tr.data('ID');
parameters.Name = 'Name goes here';
parameters.td = $td;
UpdateName(parameters);
And in the function:
var UpdateName = function(){
var local = {};
local.ID = arguments[0].ID;
local.Name = arguments[0].Name;
local.td = arguments[0].td;
local.jqXHR = $.ajax('Remote/Ajax.cfc', {
data: {
method:'UpdateName'
,returnformat:'json'
,ID:local.ID
,Name:local.Name
}
});
local.jqXHR.success(function(result){
if (result.MSG == '') {
local.td.text(local.Name).addClass('success');
} else {
local.td.addClass('err');
};
});
local.jqXHR.error(function(result){
local.td.addClass('err');
});
}
JavaScript functions are capable of using named arguments.
In your case, this could simplify your code as follows:
I modified the code so that you don’t need to keep a reference to jqXHR anymore since you aren’t doing anything with it anyway. I also moved the leading commas to the end of each line, but that is just a preference.