Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var coche =
- {
- color:"amarillo",
- volante:1,
- manual:true,
- gasolina_litros:40.5,
- llantas:{
- total:4,
- tamano:32
- },
- encender:function()
- {
- console.log("Encendiendo coche");
- }
- } //Objeto usando {}
- //////////
- var Coche_con_constructor = function(marca_que_pasaron,color_que_me_pasaron)
- {
- this.marca = marca_que_pasaron;
- this.color = color_que_me_pasaron;
- this.volante = 1;
- this.manual = true;
- this.gasolina_litros = 40.5;
- this.ventanas = "normal";
- this.llantas =
- {
- total:4,
- tamano:32
- };
- this.asientos =
- {
- color:"rosas",
- tipo:"piel"
- }
- }
- Coche_con_constructor.prototype.encender = function()
- {
- console.log("Encendiendo Coche_con_constructor");
- }
- var coche_Nissan = new Coche_con_constructor("Nissan","Plateada");
- var coche_KIA = new Coche_con_constructor("KIA","Morado");
- var coche_Ch = new Coche_con_constructor("Chevrolet","Amarillo");
- var camioneta_H = new Coche_con_constructor("Honda","Rojo");
- var arreglo_coches = [coche_Nissan,
- coche_KIA,
- camioneta_H,
- coche_Ch];
- //arreglo_coches.push(coche_Ch); //Agregar al final
- console.log(arreglo_coches[0]); //Acceder e imprimir
- //arreglo_coches[0] = 1; //Acceder y modificar
- for (var i = 0; i < arreglo_coches.length; ++i) //Acceder a todos los elementos de un arreglo
- {
- console.log( arreglo_coches[i].asientos );
- }
- console.log(arreglo_coches);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement