var Mammal=function(name){
this.name=name;
};
Mammal.prototype.get_name=function(){
return this.name;
};
Mammal.prototype.says=function(){
return this.saying || "";
};
var myMammal=new Mammal("Herb the Mammal");
var name=myMammal.get_name();alert(name)
Function.method("inherits",function(Parent){
this.protetype=new Parent();
return this;
});
//這裡報錯——沒有該方法。這個Function.method()方法不應該是系統方法嗎?
var Cat=function(name){
this.name=name;
this.saying="meow";
}
.inherits(Mammal)
.method("purr",function(n){
var i,s="";
for(i=0;i<n;i+=1){
if(s){
s+="-";
}
s+="r";
}
return s;
})
.method("get_name",function(){
return this.says()+" "+this.name+" "+this.says();
});
var myCat=new Cat("Henrietta");
var says=myCat.says();alert("says"+says)
var purr=myCat.purr(5);alert(" purr"+purr)
var name=myCat.get_name();alert(" name"+name)
cwtxz