Created
March 19, 2016 19:51
-
-
Save codejets/93a77db81e75a56daa3a to your computer and use it in GitHub Desktop.
ES6 implementation of Constructor Pattern
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
/* We now a have clean class based design like other languages out there.*/ | |
class todo { | |
constructor(name) { | |
// Adds the name of the object | |
this.name = name; | |
// As Default completed is set to false. | |
this.completed = false; | |
} | |
/* */ | |
complete() { | |
console.log('Completed!'); | |
this.completed = true; | |
} | |
toString() { | |
return this.name; | |
} | |
}; | |
// Testing Module | |
var t1 = new todo('Fix bug #2342'); | |
var t2 = new todo('Feature #23'); | |
var t3 = new todo('Call XYZ'); | |
t1.complete(); | |
console.log(t1); | |
t1.toString() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment