For any function, for example:
function my_function(arg){
switch(arg){
case 1: return 100;
case 2: return 150;
case 3: return 300;
}
}
I want to add a new case 4: 500
into the function, so it should work like:
function my_function(arg){
switch(arg){
case 1: return 100;
case 2: return 150;
case 3: return 300;
case 4: return 500;
}
}
But I don't want overwrite the function with the same script again. So I tried this way:
function my_function(arg){
switch(arg){
case 4: 500;
default: my_function(arg);
}
}
But when I call other cases 1
2
3
, the function keeps calling itself. (I understand why it happens)
Is there a way to fix this?
More generally, is there a way to overwrite a function so the new function can use the old function?
P.S. I don't want to create a function with different names that copies the old function.