title: Example of Javascript Duck Typing?
body: <p>Some programmers advise against using pseudo classical inheritance in Javascript, but advise using duck-typing and giving each object a set of capabilities.</p>
  
  <p>Is there a good example of how that is done?  I have an example down below, but it only assign function one at a time.  Can we assign a whole group of methods to an object, such as can we set a prototype of <code>OceanAnimal</code> which can "swim", "dive", and "rise", a prototype of <code>LandAnimal</code> for "run", "walk", and "jump", and let an object inherit from one or both of them?  (so a fish object can inherit or get the capabilities of <code>OceanAnimal</code>, and a turtle can get the capabilities of both <code>OceanAnimal</code> and <code>LandAnimal</code>?)</p>
  
  <pre><code>var yoyo = {
      name: "Yoyo",
      type: "turtle"
  }
  
  var simba = {
      name: "Simba",
      type: "lion"
  }
  
  var dolphy = {
      name: "Dolphy",
      type: "dolphin"
  }
  
  function swim(n) {
      console.log("My name is", this.name, ", I am a", this.type, "and I just swam", n, "feet")
  }
  
  function run(n) {
      console.log("My name is", this.name,  ", I am a", this.type, "and I just ran", n, "feet")
  }
  
  Object.prototype.respondTo = function(method) {
      return !!(this[method] &amp;&amp; (typeof this[method] === "function"));
  }
  
  yoyo.swim = swim;
  yoyo.swim(10);
  
  dolphy.swim = swim;
  dolphy.swim(80);
  
  simba.run = run;
  simba.run(200);
  
  yoyo.run = run;
  yoyo.run(2);
  
  yoyo.walk = run;
  yoyo.walk(1);
  
  console.log(simba.respondTo("swim"));
  console.log(simba.respondTo("run"));
  console.log(simba.respondTo("walk"));
  
  console.log(yoyo.respondTo("run"));
  console.log(yoyo.respondTo("walk"));
  console.log(yoyo.respondTo("fly"));
  
  if(dolphy.respondTo("run")) {
      dolphy.run(10);
  }
  
  if(dolphy.respondTo("swim")) {
      dolphy.swim(10);
  }
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>My name is Yoyo , I am a turtle and I just swam 10 feet 
  My name is Dolphy , I am a dolphin and I just swam 80 feet 
  My name is Simba , I am a lion and I just ran 200 feet 
  My name is Yoyo , I am a turtle and I just ran 2 feet 
  My name is Yoyo , I am a turtle and I just ran 1 feet 
  false 
  true 
  false 
  true 
  true 
  false 
  My name is Dolphy , I am a dolphin and I just swam 10 feet
  </code></pre>