Skip to content

Instantly share code, notes, and snippets.

@aloerina01
Last active April 27, 2017 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aloerina01/34ac696ed3f3ed1c1374e258cfa8685e to your computer and use it in GitHub Desktop.
Save aloerina01/34ac696ed3f3ed1c1374e258cfa8685e to your computer and use it in GitHub Desktop.
Immutable Object pattern with JS Module
class Immutable {
constructor(val) {
this._val = val;
}
get val() {
return this._val;
}
}
function of(val) {
return new Immutable(val);
}
export default { of };
import Immutable from './Immutable';
const immutable = Immutable.of('test value');
console.log(immutable.val); // test value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment