以下のスクリプトで悩み中。
function C(){
this.str = 'C';
}
C.prototype.f = function(){ alert('C ' + this.str); }
function D(){
this.str = 'D';
}
D.prototype.f = function(){ alert('D ' + this.str); }
D.prototype.foo = function(){
var c = new C();
c.f();
var bar = c.f;
bar();
this.hoge = c.f;
this.hoge();
}
var str = 'global';
var d = new D();
d.foo();
順に、'C C', 'C global', 'C D' になるのですが、なぜこうなるのかが まだ納得できない。うーむ……