Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <div id="log"></div>
   <script>
    function console_log(s) {
  document.getElementById('log').innerHTML += "<br>" + s;
}
  </script>
</body>
 
</html>
 
////////////////////////////////////////////////
// Javascript inheritance example
//      Animal
//      Animal : Tiger
//      Animal : Lion
// Animal
var Animal = function () {
    this.name = "animal";
};
// Tiger extends Animal
Tiger = function() {};
Tiger.prototype = new Animal();         // This is the line that creates Inheritance
//Tiger.prototype.name = "Tiger";       /* Toggle Line */
Tiger.prototype.getName = function() {
  console_log(this.name);
};
//Lion extends Animal
Lion = function() {};
Lion.prototype = new Animal();
//Lion.prototype.name = "Lion";        /* Toggle Line */
Lion.prototype.getName = function() {
  console_log(this.name);
};
// Create objects and use them
var tiger1 = new Tiger();
tiger1.name = "tiger1";
tiger1.getName();
var tiger2 = new Tiger();
//tiger2.name = "tiger2";            /* Toggle Line */
tiger2.getName();
var lion1 = new Lion();
lion1.getName();
  
    
Output

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

Dismiss x