nbagonet
7/6/2016 - 6:55 AM

一个典型的混合继承

一个典型的混合继承

var Duck = function () {
    this.color = 'yellow';
    this.quack = function () {
      alert('呱呱呱');
    };
  };
var DuckToy = new Duck();
DuckToy.play = function () {
  alert('玩玩具鸭子');
};
<a href="#" id="DuckColor">alert出Duck的color(通过DuckToy)</a>
<br>
<a href="#" id="DuckQuack">执行Duck的quack(通过DuckToy)</a>
<br>
<a href="#" id="DuckToyPlay">玩DuckToy</a>

<script>
	document.getElementById('DuckColor').onclick = function () {
    alert(DuckToy.color);
  };
  document.getElementById('DuckQuack').onclick = function () {
    DuckToy.quack();
  };
  document.getElementById('DuckToyPlay').onclick = function () {
    DuckToy.play();
  };
</script>