Last active
February 24, 2017 16:33
-
-
Save zacacollier/6ee4365425a69554f40be75cd72e1059 to your computer and use it in GitHub Desktop.
JS Bin// source http://jsbin.com/votiwet
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
// simple example | |
const addTo = (x) => (y) => x + y | |
const add10 = addTo(10) | |
const add15 = addTo(15) | |
// more verbose application of `this` context | |
const partialApply = (fn, ...staticArgs) => { | |
// return (...lexedArgs) => fn.apply(this, staticArgs.concat(lexedArgs)) | |
return (...lexedArgs) => fn(...staticArgs, ...lexedArgs) | |
} | |
const add = (x, y) => x + y | |
const add5 = partialApply(add, 5) | |
// more minimally expressed: | |
const miniApply = (f, ...x) => (...y) => f(...x, ...y) | |
const mult = (j, k) => j * k | |
const tennify = miniApply(mult, 10) | |
console.log(tennify(5)) | |
const xAndY = (x) => { | |
// implicit: this.x = x | |
// interesting - "typeof anything" is truthy | |
console.log(`y is ${typeof y ? typeof y : y}`) | |
return (y) => { | |
// implicit: this.y = y | |
return `x: ${x}, y: ${y}` | |
} | |
} | |
//const heroDogs = xAndY('lassie') | |
// console.log(heroDogs('old yeller')) | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">// simple example | |
const addTo = (x) => (y) => x + y | |
const add10 = addTo(10) | |
const add15 = addTo(15) | |
// more verbose application of `this` context | |
const partialApply = (fn, ...staticArgs) => { | |
// return (...lexedArgs) => fn.apply(this, staticArgs.concat(lexedArgs)) | |
return (...lexedArgs) => fn(...staticArgs, ...lexedArgs) | |
} | |
const add = (x, y) => x + y | |
const add5 = partialApply(add, 5) | |
// more minimally expressed: | |
const miniApply = (f, ...x) => (...y) => f(...x, ...y) | |
const mult = (j, k) => j * k | |
const tennify = miniApply(mult, 10) | |
console.log(tennify(5)) | |
const xAndY = (x) => { | |
// implicit: this.x = x | |
// interesting - "typeof anything" is truthy | |
console.log(`y is ${typeof y ? typeof y : y}`) | |
return (y) => { | |
// implicit: this.y = y | |
return `x: ${x}, y: ${y}` | |
} | |
} | |
//const heroDogs = xAndY('lassie') | |
// console.log(heroDogs('old yeller'))</script></body> | |
</html> |
This file contains 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
// Closures and spreads, all in one! | |
// simple example | |
const addTo = (x) => (y) => x + y | |
const add10 = addTo(10) | |
const add15 = addTo(15) | |
// more verbose application of `this` context | |
const partialApply = (fn, ...staticArgs) => { | |
// return (...lexedArgs) => fn.apply(this, staticArgs.concat(lexedArgs)) | |
return (...lexedArgs) => fn(...staticArgs, ...lexedArgs) | |
} | |
const add = (x, y) => x + y | |
const add5 = partialApply(add, 5) | |
// more minimally expressed: | |
const miniApply = (f, ...x) => (...y) => f(...x, ...y) | |
const mult = (j, k) => j * k | |
const tennify = miniApply(mult, 10) | |
console.log(tennify(5)) | |
// emulating class-like behavior | |
const xAndY = (x) => { | |
// implicit: this.x = x | |
// interesting - "typeof anything" is truthy | |
console.log(`y is ${typeof y ? typeof y : y}`) | |
return (y) => { | |
// implicit: this.y = y | |
return `x: ${x}, y: ${y}` | |
} | |
} | |
//const heroDogs = xAndY('lassie') | |
// console.log(heroDogs('old yeller')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment