-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path27_POO.js
More file actions
52 lines (37 loc) · 1.23 KB
/
27_POO.js
File metadata and controls
52 lines (37 loc) · 1.23 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
46
47
48
49
50
51
52
/** Programacion Orientada a Objetos**/
/** Object Literal **/
const producto ={
nombre: 'Tablet',
precio: 400
}
/** Object Constructor **/
function Producto(nombre,precio){
this.nombre = nombre;
this.precio = precio;
}
function formatearProducto(Producto){
return `El Producto ${Producto.nombre} tiene un precio de ${Producto.precio}`;
}
function Cliente(nombre,apellido){
this.nombre = nombre;
this.apellido=apellido;
}
function formatearCliente(Cliente){
return `El Cliente ${Cliente.nombre} ${Cliente.apellido}`
}
/* Prototipe: Crea una función que solo se utiliza en un objeto específico */
//Prototype para Producto
Producto.prototype.formatearProducto = function(){
return `El producto ${this.nombre} tiene un precio de $ ${this.precio}`
}
//Prototype para Cliente
Cliente.prototype.formatearCliente = function(){
return `El Cliente ${this.nombre} ${this.apellido}`;
}
const producto2 = new Producto('Monitor de 49"',400);
const producto3 = new Producto ('Ipad 6th Generation',5000);
const cliente = new Cliente('Santiago','Naranjo');
console.log(cliente);
console.log(cliente.formatearCliente());
console.log(producto2.formatearProducto());
console.log(producto3.formatearProducto());