Skip to content

Instantly share code, notes, and snippets.

@carlosvillu
Created October 10, 2011 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosvillu/1275826 to your computer and use it in GitHub Desktop.
Save carlosvillu/1275826 to your computer and use it in GitHub Desktop.
Como crear clases y herencias en JS
var Forma = function(){};
Forma.prototype = {
getArea: function()
{
console.log('Get Area from Forma');
}
};
var Cuadrado = function()
{
var __super__ = Forma;
__super__.apply(this);
__super__ = null;
};
Cuadrado.prototype = new Forma();
Cuadrado.prototype = {
getArea: function()
{
console.log('Get Area from Cuadrado');
}
};
var Circulo = function()
{
var __super__ = Forma;
__super__.apply(this);
__super__ = null;
};
Circulo.prototype = new Forma();
Circulo.prototype = {
getArea: function()
{
console.log('Get Area from Circulo');
}
};
var Triangulo = function()
{
var __super__ = Forma;
__super__.apply(this);
__super__ = null;
};
Triangulo.prototype = new Forma();
Triangulo.prototype = {
getArea: function()
{
console.log('Get Area from Triangulo');
}
};
(new Forma()).getArea();
(new Cuadrado()).getArea();
(new Circulo()).getArea();
(new Triangulo()).getArea();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment