Created
November 18, 2011 18:56
-
-
Save flockonus/1377395 to your computer and use it in GitHub Desktop.
Pseudo-Classical-OO
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
/** | |
* @author Fabiano PS | |
*/ | |
( function(){ | |
window.App = {} | |
// define uma pessoa normal | |
App.Person = function(name){ | |
this.name = name || "anon" | |
this.iq = 100 | |
this.fortune_number = Math.floor(Math.random()*100) | |
} | |
App.Person.prototype.sayName = function() { | |
return (this.name+"!") | |
} | |
App.Person.prototype.sayIQ = function() { | |
return (this.iq) | |
} | |
// define um genio da humanidade | |
App.Genius = function(name) { | |
App.Person.call( this, name ) | |
this.iq = 9000 | |
}; | |
// inherits All methods from Pessoa | |
App.Genius.prototype = App.Person.prototype | |
App.Genius.prototype.solveNP = function() { | |
return "eureka!" | |
}; | |
})() | |
var p = new App.Person('Jon') | |
console.log( "A Person:", p.sayName(), p.fortune_number, p.sayIQ() ) | |
var g = new App.Genius( 'Eugenios' ) // mantem o ki elevado, e tem um fortune) | |
console.log( "A Genious:", g.sayName(), g.fortune_number, g.sayIQ(), g.solveNP() ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment