On Fri, Mar 16, 2012 at 3:04 PM, David Bruant <[email protected]> wrote:
> Unfortunately, methods on prototype require to have properties that are
> public.
>
> If you avoid prototype methods, all your attributes and private methods can
> be shared by public method scopes.
I think you are mixing up interface and implementation here, in a funky way ;-)
The interface of the 'prototype', a pointer to a table for fallback
lookup, allows implementation inheritance. But it does not demand it,
it's just a choice you may make.
You can, for example, create an implementation hierarchy, then
encapsulate it in a an interface hierarchy. The functions on the
.prototype for the interface may be pointers to functions on the
encapsulated implementation.
Something like:
var Foo = (function makeFoo(impl) {
function Foo() {
impl.call(this, ...);
}
Foo.prototype = {
bar: impl.bar,
baz: impl.baz
};
return Foo;
})(theImpl);
So prototype does not mean non-encapsulation.
jjb
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss