Skip to content

Instantly share code, notes, and snippets.

@rektide
Created October 12, 2018 19:19
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 rektide/bcecefd644aa9caaad290d360de02552 to your computer and use it in GitHub Desktop.
Save rektide/bcecefd644aa9caaad290d360de02552 to your computer and use it in GitHub Desktop.
Properties the declarative way
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