Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="protoVsprototype" />
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
function Heroe(){
  this.malvado = false;
  this.getTipo = function() {
    return this.malvado ? "Malo" : "Bueno";
  };
}
Heroe.prototype.atacar = function() {
  return this.malvado ? "Ataque con Joker" : "Ataque con Batman";
}
var robin = new Heroe();
console.log(robin.getTipo());   // Bueno
console.log(robin.atacar());     // Ataque con Batman
var lexLuthor = new Heroe();
lexLuthor.malvado = true;
console.log(lexLuthor.getTipo());   // Malo
console.log(lexLuthor.atacar());     // Ataque con Joker
var policia = Object.create(robin);
console.log(policia.getTipo());     // Bueno
console.log(policia.__proto__.atacar());    // Ataque con Batman
Output

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

Dismiss x
public
Bin info
aitormedran0pro
0viewers