Here are the code:
var
shuriken = {
hit:function(who){alert("pierced the "+who+" armor");}
},
sword = {
hit:function(who){alert("Chopped the "+who+" in half");}
};
function Samurai(weapon){
return {
Attack:function(who){
weapon.hit(who);
}
}
}
container.register("samurai",Samurai);
var warrior1 = container.byConstructor("samurai",shuriken),
warrior2 = container.byConstructor("samurai",sword);
warrior1.Attack("The evildoers");
warrior2.Attack("The evildoers");
So simple, So clear!