Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to define same function with multiple names in javascript

I have a requirement like, i need to execute a js code for some screens in my application and i need to name the function with viewid like myScreen1().. myScreen3().

But as the function definition is same for all the function names, is there any way to declare such that all the function names will refer to same definition?

like image 352
dush Avatar asked Jul 17 '26 13:07

dush


1 Answers

Following will work, but maybe you should rethink your design as most likely it is also possible using only one function name.

var func = function() {
    // definition goes here
}
var myScreen1 = func;
var myScreen2 = func;
like image 125
Peter van der Wal Avatar answered Jul 19 '26 06:07

Peter van der Wal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!