Last active
August 23, 2016 06:55
-
-
Save BenBestmann/438e5c80f0ddb37edcb1040152ce4843 to your computer and use it in GitHub Desktop.
ES6 Constructor Pattern
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
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