JQuery - Can I rename a js function?


I hope someone can help me.

I have a function like

<script language="JavaScript" type="text/javascript">
    function my_test()
    {
     ... some code ... 
    }
</script>

Is it possible to rename (or clone) this function in my_test_2()?

Thanks in advance!
Peter

+5
source share
2 answers

Functions are first class objects in Javascript. You can do:

var my_test_2 = my_test;
my_test_2();  // Calls the same function as my_test() does.
+16
source
my_test_2 = my_test;

Functions are like variables, so my_test_2 will be a reference to the original.

+4
source

All Articles