Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery - Is it possible to rename a js function?


hope someone can help me.

I have a function like

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

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

Thanks in advance!
Peter

like image 685
Peter Avatar asked May 27 '11 18:05

Peter


People also ask

Can you name a function in jQuery?

A lot of jQuery functions are implemented as name: function () {}. For example, the following is the definition of the jQuery function grep. function grep( elems, callback, inv ) { var retVal, ret = [], i = 0, length = elems. length; inv = !!

How to name functions in JavaScript?

A JavaScript function is defined with the function keyword, followed by a name, followed by parentheses (). Function names can contain letters, digits, underscores, and dollar signs (same rules as variables).

What does invoke mean in JavaScript?

Invoking a JavaScript FunctionThe code inside a function is executed when the function is invoked. It is common to use the term "call a function" instead of "invoke a function". It is also common to say "call upon a function", "start a function", or "execute a function".

What is js function?

A function in JavaScript is similar to a procedure—a set of statements that performs a task or calculates a value, but for a procedure to qualify as a function, it should take some input and return an output where there is some obvious relationship between the input and the output.


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.
like image 59
Frédéric Hamidi Avatar answered Oct 02 '22 06:10

Frédéric Hamidi


my_test_2 = my_test;

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

like image 28
dkruythoff Avatar answered Oct 02 '22 08:10

dkruythoff