Skip to content

Instantly share code, notes, and snippets.

@forestbelton
Created February 12, 2020 06:18
Show Gist options
  • Save forestbelton/05650024e6e389dc62bab24dbd3e6e7d to your computer and use it in GitHub Desktop.
Save forestbelton/05650024e6e389dc62bab24dbd3e6e7d to your computer and use it in GitHub Desktop.
types without class
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