Skip to content

Instantly share code, notes, and snippets.

@codejets
Created March 19, 2016 19:51
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 codejets/93a77db81e75a56daa3a to your computer and use it in GitHub Desktop.
Save codejets/93a77db81e75a56daa3a to your computer and use it in GitHub Desktop.
ES6 implementation of Constructor Pattern
/* 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