Last active
November 5, 2017 13:30
-
-
Save YoneMoreno/ed8a30fbdbfcca9440bdadbdd6c452d0 to your computer and use it in GitHub Desktop.
ConstructorPattern in JS https://app.pluralsight.com/player?course=javascript-practical-design-patterns&author=jonathan-mills&name=javascript-practical-design-patterns-m3&clip=2&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 = function(name){ | |
this.name=name; | |
this.completed=false; | |
this.complete = function(){ | |
console.log('completing task: ' + this.name); | |
this.completed=true; | |
} | |
this.save = function(){ | |
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(); |
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); | |
}; | |
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