Created
July 9, 2013 14:37
-
-
Save reu/5957848 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
function inherit(child, parent) { | |
child.prototype = Object.create(parent.prototype); | |
child.prototype.constructor = child; | |
} | |
var Person = function Person(firstName, lastName) { | |
if (!firstName || !lastName) throw "Primeiro e último nome requerido!"; | |
this.firstName = firstName; | |
this.lastName = lastName; | |
} | |
Person.prototype.fullName = function() { | |
return this.firstName + " " + this.lastName; | |
} | |
var Ninja = function Ninja(firstName, lastName, stars) { | |
Person.call(this, firstName, lastName); // super | |
this.stars = 10; | |
} | |
// Note que eu herdei antes de definir o resto das funções | |
// no prototype do Ninja. | |
inherit(Ninja, Person); | |
Ninja.prototype.throwStar = function(first_argument) { | |
this.stars -= 1; | |
return "Star throwed"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment