Skip to content

Instantly share code, notes, and snippets.

@BenBestmann
Last active August 23, 2016 06:55
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 BenBestmann/438e5c80f0ddb37edcb1040152ce4843 to your computer and use it in GitHub Desktop.
Save BenBestmann/438e5c80f0ddb37edcb1040152ce4843 to your computer and use it in GitHub Desktop.
ES6 Constructor Pattern
class Car {
constructor(opts) {
this.model = opts.model;
this.year = opts.year;
this.miles = opts.miles;
}
toString() {
return this.model + ' has driven ' + this.miles + ' miles';
}
}
// Usage
var civic = new Car({
model: 'Honda',
year: 2001,
miles: 50000
});
civic.toString();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment