-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path28_clases.js
More file actions
45 lines (35 loc) · 1.05 KB
/
28_clases.js
File metadata and controls
45 lines (35 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* Clases En JavaScript */
class Producto{
constructor(nombre,precio){
this.nombre = nombre;
this.precio = precio;
}
formatearProducto(){
return `El producto ${this.nombre} tiene un precio de $ ${this.precio}`;
}
precioProducto(){
return `${this.nombre} vale: ${this.precio}$ `
}
}
const producto2 = new Producto('Monitor Curvo de 49"',800);
const producto3 = new Producto('Laptop',300);
// console.log(producto2);
// console.log(producto3);
// console.log(producto2.formatearProducto());
// console.log(producto2.precioProducto());
/* Herencia */
class Libro extends Producto{
constructor(nombre,precio,isbn){
super(nombre,precio);
this.isbn = isbn;
}
formatearProducto(){
return `${super.formatearProducto()} y su ISBN es: ${this.isbn}`;
}
obtenerPrecio(){
return `${super.precioProducto()}`;
}
}
const libro = new Libro("La Revolucion de JavaScript",300,'13123141');
console.log(libro.formatearProducto());
console.log(libro.obtenerPrecio());