Last active
November 5, 2017 13:46
-
-
Save YoneMoreno/c0941fce047872b23a92e112c388fd20 to your computer and use it in GitHub Desktop.
Usingconstructor pattern in Node https://app.pluralsight.com/player?course=javascript-practical-design-patterns&author=jonathan-mills&name=javascript-practical-design-patterns-m3&clip=5&mode=live
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
var Task = require('./taskConstructorPattern'); | |
var task1 = new Task('create a demo for constructors'); | |
var task2 = new Task('create a demo for modules'); | |
var task3 = new Task('create a demo for singletons'); | |
var task4 = new Task('create a demo for prototypes'); | |
task1.complete(); | |
task2.save(); | |
task3.save(); | |
task4.save(); |
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
var Task = function(name){ | |
this.name=name; | |
this.completed=false; | |
} | |
Task.prototype.complete = function () { | |
console.log('completing task: ' + this.name); | |
this.completed=true; | |
}; | |
Task.prototype.save = function () { | |
console.log('saving Task: ' + this.name); | |
}; | |
module.exports = Task; |
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
'use strict'; | |
class Task { | |
constructor(name){ | |
this.name=name; | |
this.completed=false; | |
} | |
complete() { | |
console.log('completing task: ' + this.name); | |
this.completed=true; | |
}; | |
save() { | |
console.log('saving Task: ' + this.name); | |
}; | |
} | |
var task1 = new Task('create a demo for constructors'); | |
var task2 = new Task('create a demo for modules'); | |
var task3 = new Task('create a demo for singletons'); | |
var task4 = new Task('create a demo for prototypes'); | |
task1.complete(); | |
task2.save(); | |
task3.save(); | |
task4.save(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment