Created
September 8, 2018 16:58
-
-
Save jmakeig/0ad5a73aad8422230c2a220f221a19f7 to your computer and use it in GitHub Desktop.
Factory for classes using a closure to set initial state.
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
'use strict'; | |
class Component { | |
constructor(props) { | |
this._props = props; | |
} | |
get props() { | |
return this._props; | |
} | |
set props(p) { | |
this._props = p; | |
} | |
} | |
function Factory(stuff) { | |
class Thing extends Component { | |
constructor() { | |
super(stuff); | |
} | |
} | |
return Thing; | |
} | |
const T = Factory('T'); | |
new T().props; // 'T' | |
const U = Factory('U'); | |
new U().props; // 'U' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment