Created
October 30, 2017 09:37
-
-
Save savelichalex/2f48ddbad4b36c927a52f87a04b2ea0d to your computer and use it in GitHub Desktop.
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(of) { | |
Object.keys(of).forEach(key => Object.defineProperty(this, key, { enumerable: true, get: () => this.of[key] })); | |
Object.defineProperty(this, "of", { enumerable: false, get: () => of }); | |
} | |
set(key, value) { | |
return new this.constructor({ ...this.of, [key]: value }); | |
} | |
} | |
class Foo extends Immutable { | |
constructor(obj) { | |
super(obj); | |
this.fooClass = true; | |
} | |
setFoo(val) { | |
return super.set("foo", val); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment