I have a simple question related to one-line programming. First an example:
function test(a)
{
var b=a.toString();
return b.replace("a","b");
}
It's very simple (this function is, of course, useless), but the question here is little more complicated: What if I was to do this in one line? I have my thoughts, but tell me does this work properly with respect to memory cleanup:
function test(a)
{
return (arguments[1]=a.toString()).doSomething().doSomethingMore(arguments[1]);
}
This is, of course, an example, but the idea is simple: use arguments as a container for local variables - I'm not sure, but from what I know, when function are over, arguments are deleted also ? Or does creating new elements in arguments makes this element defined globally? From my tests it seems that I'm correct, but I'm curious to see if anyone has tried this? Is this a safe and clean solution?: ) Thanks for any comments.
Here are more real problem with One-Line script problem:
function (number,limiter)
{
return ((arguments[2] = number.toString().replace(
new RegExp("(\\d+)(\\d{3})($|"+limiter+")"),
'$1'+limiter+'$2$3')) == number) ?
arguments[2] :
arguments.callee(arguments[2],limiter);
}
This one line function do things with given string and return it or parse it recursively to the same function. (on other thread i show how this could be done without recursion, but this is not a case of a problem).