Here is the idea: I want to be able to make it so that I can change the order in which inputs matter in a function. Lets say that the normal function looks as such:
var f = function(a,b,c,d){
return a * b / c + d;
}
I want to be able to redefine the function, so that when a user calls f(w,x,y,z)
if a variable(lets say changed
) is true, it acts as if the user called f(w,z,y,x)
! (not specifically in reverse order, just a different order than original function)
If I wanted to write a separate function that acted that way I could do the following:
var newF = function(a,b,c,d){
if(changed === true){
return f(c,d,b,a);
}
else{
return f(a,b,c,d);
}
}
and then replace all f
calls with newF
calls, but that is not what I am asking.
Is it possible to redefine a function with the same name as the actual function, and how that would be done? If I cannot, please explain why not.
Explanation:
The reason I want to do this is because I have an app that has a function to make everything naturally sound (like points in a line being straight), but if I switch some of the values, it creates a fun, unrealistic, situation, which I thought would be a fun option to implement. My option above is doable, and I could use it, but I was just wondering if it is possible to keep it within the same function name