Skip to content

Instantly share code, notes, and snippets.

@jose4125
Created August 25, 2016 17:57
Show Gist options
  • Select an option

  • Save jose4125/0e9f71c2af3ccf3ad96299b733a4725b to your computer and use it in GitHub Desktop.

Select an option

Save jose4125/0e9f71c2af3ccf3ad96299b733a4725b to your computer and use it in GitHub Desktop.
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