Last active
April 27, 2017 03:24
-
-
Save aloerina01/34ac696ed3f3ed1c1374e258cfa8685e to your computer and use it in GitHub Desktop.
Immutable Object pattern with JS Module
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
class Immutable { | |
constructor(val) { | |
this._val = val; | |
} | |
get val() { | |
return this._val; | |
} | |
} | |
function of(val) { | |
return new Immutable(val); | |
} | |
export default { of }; |
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
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