Created
November 8, 2018 20:20
-
-
Save lk321/a2d0cb3cbb98ea1fd9d428debeb3543a to your computer and use it in GitHub Desktop.
Clases en js
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
// 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