Ejemplos objetos

var pepe = {
firstName:"John",
lastName:"Doe",
age:50,
eyeColor:"blue",
completo:function(){
return this.firstName+" "+this.lastName;
},
mayorEdad:function(){
return this.age>=18;
}
};

function Person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
}

var ana=new Person("Ana","Pi",40,"azul")

var juan=new Person("Juan","Perez",50,"marrón")
for (var p in pepe){
if (typeof pepe[p]!=="function"){
console.log(p+" - "+pepe[p]);
}
else{
console.log(p+" - "+pepe[p]());
}
}

function normal(){
return "Hola";
}

var noNormal=function(){
return "adios";
}

noNormal=function(){
return "funcion nueva";
}

Publicado por

Juan Pablo Fuentes

Formador de programación y bases de datos