Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="personaOO" />
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
var Persona = function(nombre, apellido1) {
  this.nombre = nombre;
  this.apellido1 = apellido1;
};
Object.defineProperties(Persona.prototype, {  
  nombreCompleto: {
    get: function() { 
      return this.nombre + " " + this.apellido1;
    },
    enumerable: true
  }
});
Persona.prototype.saluda = function(persona) {  
  if (persona instanceof Persona) {
    return "Hola " + persona.nombreCompleto;
  } else {
    return "Hola colega";
  }
};
var batman = new Persona("Bruce", "Wayne");
console.log(batman.nombreCompleto); // Bruce Wayne
console.log(batman.saluda()); // Hola colega
var superman = new Persona("Clark", "Kent");
console.log(batman.saluda(superman)); // Hola Clark Kent
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
aitormedran0pro
0viewers