Last active
August 6, 2023 22:19
-
-
Save KattyaCuevas/adac765af5cc4fcf5c6e to your computer and use it in GitHub Desktop.
Ejemplos Taller de JavaScript - Session 2: Programación Orientada a Objetos
This file contains 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
// Con el contructor Function() | |
var lanzaLlamas = new Function( | |
'console.log("Vamos charmandar, usa lanzallamas")' | |
); | |
// Declaración de funciones | |
function ascuas() { | |
console.log("Charmandar, ascuas"); | |
} | |
// Función como una expresión | |
var golpeCabeza = function() { | |
console.log("Charmandar usa golpe de cabeza!"); | |
} | |
// Función con parametros | |
var bienvenida = new Function('nombre', | |
'console.log("Bienvenido " + nombre)'); | |
function bienvenida(nombre) { | |
console.log("Bienvenido " + nombre); | |
} | |
var bienvenida = function() { | |
console.log("Bienvenido " + nombre); | |
} |
This file contains 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
function pokemon(nombre, tipo, debilidad, especie, genero, habilidad) { | |
this.nombre = nombre; | |
this.tipo = tipo; | |
this.debilidad = debilidad; | |
this.especie = especie; | |
this.genero = genero; | |
this.habilidad = habilidad; | |
// Metodo para mostrar informacion | |
this.mostrarTipo = function() { | |
console.log(this.nombre + ' es de tipo ' + this.tipo); | |
} | |
// Método para cambiar nombre del objeto actual | |
this.cambiarNombre = function(nombre) { | |
this.nombre = nombre; | |
} | |
} |
This file contains 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
var charmander = new Object(); | |
pokemon1.nombre = 'Charmander'; | |
pokemon1.tipo = 'Fuego'; | |
pokemon1.debilidad = 'Tierra'; | |
pokemon1.especie = 'Lagartija'; | |
pokemon1.genero = 'macho'; | |
pokemon1.habilidad = 'Mar llamas'; | |
// Object Literal | |
var bulbasaur = { | |
nombre: 'Bulbasaur', | |
tipo: 'Planta', | |
debilidad: 'Fuego', | |
especie: 'Semilla', | |
genero: 'macho', | |
habilidad: 'Espesura' | |
}; | |
// Usando el constructor | |
var pikachu = new pokemon('Pikachu','Electrico','Tierra','Ratón','macho'); | |
// Utilizando metodos anteriores | |
pikachu.mostrarTipo(); | |
pikachu.cambiarNombre('pika'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment