Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. var coche =
  2. {
  3. color:"amarillo",
  4. volante:1,
  5. manual:true,
  6. gasolina_litros:40.5,
  7. llantas:{
  8. total:4,
  9. tamano:32
  10. },
  11. encender:function()
  12. {
  13. console.log("Encendiendo coche");
  14. }
  15. } //Objeto usando {}
  16. //////////
  17. var Coche_con_constructor = function(marca_que_pasaron,color_que_me_pasaron)
  18. {
  19. this.marca = marca_que_pasaron;
  20. this.color = color_que_me_pasaron;
  21. this.volante = 1;
  22. this.manual = true;
  23. this.gasolina_litros = 40.5;
  24. this.ventanas = "normal";
  25. this.llantas =
  26. {
  27. total:4,
  28. tamano:32
  29. };
  30. this.asientos =
  31. {
  32. color:"rosas",
  33. tipo:"piel"
  34. }
  35. }
  36. Coche_con_constructor.prototype.encender = function()
  37. {
  38. console.log("Encendiendo Coche_con_constructor");
  39. }
  40. var coche_Nissan = new Coche_con_constructor("Nissan","Plateada");
  41. var coche_KIA = new Coche_con_constructor("KIA","Morado");
  42. var coche_Ch = new Coche_con_constructor("Chevrolet","Amarillo");
  43. var camioneta_H = new Coche_con_constructor("Honda","Rojo");
  44.  
  45. var arreglo_coches = [coche_Nissan,
  46. coche_KIA,
  47. camioneta_H,
  48. coche_Ch];
  49. //arreglo_coches.push(coche_Ch); //Agregar al final
  50.  
  51. console.log(arreglo_coches[0]); //Acceder e imprimir
  52. //arreglo_coches[0] = 1; //Acceder y modificar
  53.  
  54. for (var i = 0; i < arreglo_coches.length; ++i) //Acceder a todos los elementos de un arreglo
  55. {
  56. console.log( arreglo_coches[i].asientos );
  57. }
  58. console.log(arreglo_coches);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement