// 新しい木クラスを作成します
function Tree(name, leaf, bark) {
this.name = name;
this.leaf = leaf;
this.bark = bark;
}
// 関数を追加します
Tree.prototype.describe = function() {
return this.name + ": leaf=" + this.leaf +", bark=" + this.bark;
}
// 追加した関数のテスト
var beech = new Tree("1", "2", "3");
alert(beech.describe());
// 新しい犬クラスを作成
function Dog(name, bark) {
this.name = name;
this.bark = bark;
}
// 犬クラスをインスタンス化
var snowy = new Dog("snowy", "wau!");
// 木クラスの関数を借用
var tmpFunc = beech.describe;
alert(tmpFunc.call(snowy));