Mon 04 Feb 2013 06:14:25 PM UTC, original submission:
Consider this situation:
function Foo()
{
}
Foo.prototype.bar = function( val )
{
this.foo = val;
}
var Foo2 = Class( 'Foo2' ).extend( Foo,
{
'public setBar': function( val )
{
this.bar( val );
},
'public getBar': function()
{
return this.foo;
},
} );
Now, consider that we have:
var foo = Foo2();
foo.bar( 'moo' );
foo.foo // "moo"
foo.getBar() // "moo"
foo.setBar( 'baz' );
foo.foo // "moo"
foo.getBar() // "baz"
The problem is that 'foo' isn't defined as a property on the prototype---it is simply assigned during a method call. This is a problem because ease.js therefore does not create a proxy to it and, as such, the context (bound to 'this') is the private visibility object when Foo.bar() is called within the scope of the class. However, when it's called outside the scope of the class, it is the public visibility object.
With the understanding that these properties would be implicitly public in pure ECMAScript, it may suffice to simply have ease.js wrap each method of the prototype being inherited (if it recognizes that it is not a class), which would then ensure that 'this' references the public visibility object. Of course, that would mean that the supertype would not have access to protected members.
|