ETHproductions / japt

Japt 1.4.5, the other JavaScript golfing language
http://ethproductions.github.io/japt
74 stars 10 forks source link

Add wrappers for Function.prototype.call() and Function.prototype.apply() #49

Open Bubbler-4 opened 6 years ago

Bubbler-4 commented 6 years ago

When a function is stored into a variable, say U, there is no simple way to call it, especially with arguments. It is because, if you type U(, the transpiler inserts a comma between U and (. But vanilla JS has a couple of handy tools for that:

Since plenty of slots are still available for Function.prototype in Japt, I suggest to add these two methods as one-char aliases.

In place of apply, there is a more general alternative: F.d(x) = F(...x). This not only spreads array elements, but also individual chars of a string. It's a useful tool to have in vanilla JS for something like Math.max(..."12345") which calculates the largest digit of a number (though I can't think of use cases in Japt right now).