Last active
October 5, 2018 15:04
-
-
Save babakness/56da19ba85e0eaa43ae5577bc0064456 to your computer and use it in GitHub Desktop.
Helpers for creating class like functions that can be invoked without new
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
const assoc = ( prop, value, obj ) => | |
Object.assign( {}, obj, { [prop]: value }) | |
const reducer = ( $values, accumulate, [key,val] ) => assoc( key, val.bind( undefined, ...$values ), accumulate ) | |
export const bindValuesToMethods = ( $methods, ...$values ) => | |
Object.entries( $methods ).reduce( reducer.bind( undefined, ...$values ), {} ) | |
export const prepareInstance = (instanceMethods, staticMethods = ({}) ) => Object.assign( | |
bindValuesToMethods.bind( undefined, instanceMethods ), | |
staticMethods | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
should be
else error will happed