Created
February 12, 2020 06:18
-
-
Save forestbelton/05650024e6e389dc62bab24dbd3e6e7d to your computer and use it in GitHub Desktop.
types without class
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
const dataclass = f => function() { | |
Object.entries(f(...arguments)).forEach(([k, v]) => { | |
this[k] = v | |
}) | |
} | |
const F = dataclass((x, y) => ({x, y})) | |
const f = new F(1, 2) | |
console.log(f instanceof F) // "true" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment