Skip to content

Instantly share code, notes, and snippets.

@jmakeig
Created September 8, 2018 16:58
Show Gist options
  • Save jmakeig/0ad5a73aad8422230c2a220f221a19f7 to your computer and use it in GitHub Desktop.
Save jmakeig/0ad5a73aad8422230c2a220f221a19f7 to your computer and use it in GitHub Desktop.
Factory for classes using a closure to set initial state.
'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