Forked from babakness/create-class-like-functions.js
Created
October 5, 2018 15:04
-
-
Save pre1ude/03bff2c431d6c4586fc20b8b49658195 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