Last active
June 27, 2016 05:34
-
-
Save stefanfrede/0ac81b70d56f34bdc1543ac0278106a1 to your computer and use it in GitHub Desktop.
Quickly and simply apply a single argument.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// leftmost | |
const callFirst = (fn, larg) => | |
function (...rest) { | |
return fn.call(this, larg, ...rest); | |
} | |
// rightmost | |
const callLast = (fn, rarg) => | |
function (...rest) { | |
return fn.call(this, ...rest, rarg); | |
} | |
const greet = (me, you) => | |
`Hello, ${you}, my name is ${me}`; | |
const heliosSaysHello = callFirst(greet, 'Helios'); | |
heliosSaysHello('Eartha') | |
//=> 'Hello, Eartha, my name is Helios' | |
const sayHelloToCeline = callLast(greet, 'Celine'); | |
sayHelloToCeline('Eartha') | |
//=> 'Hello, Celine, my name is Eartha' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment