I try to define prototype functions from an array. As in the following example : my black rabbit should say 'toto' but it doesn't say it ! Why ?
function Rabbit ( type ) {
this.type = type ;
}
var funcs = ["says", "doesnt_say"];
for(var i=0;i<funcs.length;i++)
{
var f = funcs[i];
Rabbit.prototype[f] = function ( line ) {
alert(" The " + this.type + " rabbit "
+ f + " '" + line + " '") ;
};
}
var blackRabbit = new Rabbit ("black") ;
blackRabbit.says("toto");
Visible on http://jsfiddle.net/xou11bgu/