Created
August 25, 2016 17:57
-
-
Save jose4125/0e9f71c2af3ccf3ad96299b733a4725b to your computer and use it in GitHub Desktop.
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
| console.log('========================== PROTOTYPAL ================================') | |
| var ProtoTask = { | |
| constructor: function(title, complete) { | |
| this.title = title; | |
| this.isComplete = complete || false; | |
| }, | |
| complete: function() { | |
| return this.isComplete; | |
| }, | |
| msg: function() { | |
| console.log(this.title + ' is ' + (this.isComplete ? 'completed' : 'not completed yet')); | |
| } | |
| } | |
| var myPrTask = Object.create(ProtoTask); | |
| console.log(myPrTask) | |
| myPrTask.constructor('task1'); | |
| var myPrTask2 = Object.create(ProtoTask); | |
| myPrTask2.constructor('task2', true) | |
| myPrTask2.sayhi = function() {} | |
| console.log(myPrTask) | |
| console.log(myPrTask.msg()) | |
| console.log(myPrTask2) | |
| console.log(myPrTask2.complete()) | |
| var UrgentProtoTask = Object.create(ProtoTask); | |
| UrgentProtoTask.constructor = function(title, complete) { | |
| ProtoTask.constructor.call(this, title, complete); | |
| this.typeTask = 'urgent' | |
| }; | |
| UrgentProtoTask.msg = function() { | |
| console.log(ProtoTask.msg.call(this) + | |
| ', but this is ' + this.typeTask) | |
| } | |
| var myUrgPrTask = Object.create(UrgentProtoTask); | |
| myUrgPrTask.constructor('urgent task') | |
| console.log(myUrgPrTask) | |
| console.log(myUrgPrTask.msg()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment