Overwriting arguments object for a Javascript function

Posted by Ian Storm Taylor on Stack Overflow See other posts from Stack Overflow or by Ian Storm Taylor
Published on 2011-02-15T07:07:45Z Indexed on 2011/02/15 7:25 UTC
Read the original article Hit count: 293

If I have the following:

    // Clean input.
    $.each(arguments, function(index, value) {

        arguments[index] = value.replace(/[\W\s]+/g, '').toLowerCase();
    });

Would that be a bad thing to do? I have no further use for the uncleaned arguments in the function, and it would be nice not to create a useless copy of arguments just to use them, but are there any negative effects to doing this?

Ideally I would have done this, but I'm guessing this runs into problems since arguments isn't really an Array:

    arguments = $.map(arguments, function(value) {

        return value.replace(/[\W\s]+/g, '').toLowerCase();
    });

Thanks for any input.

EDIT: I've just realized that both of these are now inside their own functions, so the arguments object has changed. Any way to do this without creating an unnecessary variable?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery