-1

I've been trying to find out how to create shortcuts for arguments for a while now, but I can't find anything online for some reason.

Let's say you wanted to, alert('Hello World') but you did not want to have to type alert and instead something like, exampleshortcut('Hello World'). Would this be possible, or am I just being dumb?

j08691
  • 190,436
  • 28
  • 232
  • 252
Strobilus
  • 9
  • 2

3 Answers3

0

If you're asking how to alias functions then you could just assign it to a variable, though this is generally considered an anti-pattern if you are making no other changes.

const exampleShortcut = alert;
exampleShortcut('Hello World');
Zweih
  • 147
  • 8
0

Functions are first-class objects. You can copy them just like any other value.

const lert = alert;

lert("Hello, world");

Note that doing so may break functions which depend on the this value. Your example case won't though.

Quentin
  • 800,325
  • 104
  • 1,079
  • 1,205
0

You can assign the function to a "reference". (but i think you should not).

a = alert;
a('Hello world');
Maxime
  • 26
  • 4