RE: Faking host objects

> > // let fooInstance be an instance of Foo, got somehow from your API
> > Foo.prototype.test2=Foo.prototype.test;
> > fooInstance.test2(); // fail
> 
> The above must fail, because test2 is a copy of test whose "this" has changed.   


This is not the real issue, as this does not work better:

 

    Foo.prototype.test2=function() {};

    fooInstance.test2(); // Uncaught TypeError: Object #<Foo> has no method 'test2' 

 

The problem is that Foo.prototype is not the ‘real’ Object.getPrototypeOf(fooInstance), but an object that inherits its properties; adding more stuff on Foo.prototype doesn’t affect the other one.

Received on Saturday, 29 December 2012 18:18:20 UTC