Created
October 12, 2018 19:19
-
-
Save rektide/bcecefd644aa9caaad290d360de02552 to your computer and use it in GitHub Desktop.
Properties the declarative way
This file contains hidden or 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
const $frequency = Symbol.for("Overthruster:frequency") | |
export class Overthruster | |
{ | |
constructor({frequency}={}){ | |
this[$frequency]= frequency | |
} | |
get frequency(){ | |
return this[ $frequency] | |
} | |
} | |
// Things I like about this approach: | |
// * Object.getOwnPropertyDescriptor(Overthruster.prototype.frequency) returns something! There's some reflection! | |
// * Getter/setters can be extended using .super. | |
// * The underlying state is accessible, which to me is a major positive. User beware, but it's obvious you're going slightly far afield. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment