the object F has a function stored as this.fn and this.state.fn. can be called successfully as f.fn() but not as f.state.fn()
function F( i, f ) {
this.i = i;
this.state = { 'fn':f };
this.f = f;
};
F.prototype.inc = function() { this.i++ };
F.prototype.fn = function() { this.state.fn() };
f1 = new F( 1, function() { console.log( this.i ); } );
f1.f(); // this works
f1.inc(); // this works
f1.state.fn; // prints the function
f1.fn(); // undefined!
f1.state.fn(); // undefined!
the problem seems to be that the function is stored in the object state, because this works:
f1.state.fn.call( f1 );
F.prototype.fn = function() { this.state.fn.call(this); };
which seems to imply that the this context within F.state.fn is not F but rather F.state - which to me is completely counter-intuitive - is this right!?