Skip to content

Instantly share code, notes, and snippets.

@lk321
Created November 8, 2018 20:20
Show Gist options
  • Save lk321/a2d0cb3cbb98ea1fd9d428debeb3543a to your computer and use it in GitHub Desktop.
Save lk321/a2d0cb3cbb98ea1fd9d428debeb3543a to your computer and use it in GitHub Desktop.
Clases en js
// Old
function Poligono(height, width) {
this.height = height;
this.width = width;
}
Poligono.prototype.area = function() {
return this.height * this.width;
};
var c = new Poligono(10, 10);
console.log(c.area());
// ES6
class Poligono {
constructor(height, width) {
this.height = height;
this.width = width;
}
get area() {
return this.calcArea();
}
calcArea() {
return this.height * this.width;
}
}
var c = new Poligono(10, 10);
console.log(c.area);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment