Last active
January 22, 2018 18:16
-
-
Save barneycarroll/0111cb142989f9f645878939e18803f7 to your computer and use it in GitHub Desktop.
Patchinko's overloaded module re-written in terse yet spacious expressions (source: https://github.com/barneycarroll/patchinko/blob/master/overloaded.js)
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
export default function O(a){ | |
return ( | |
arguments.length == 1 | |
? | |
typeof a != 'function' | |
? | |
new O(a => O(b, a)) | |
: | |
this instanceof O | |
? | |
( | |
this.apply = b => a(b), | |
this | |
) | |
: | |
new O(b) | |
: | |
[...arguments].reduce(({}, b) => ( | |
Object.entries(b).forEach(([key, val]) => ( | |
val == O | |
? | |
delete a[key] | |
: | |
a[key] = | |
val instanceof O | |
? | |
val.apply(a[key]) | |
: | |
val | |
)), | |
a | |
)) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment