So for some reason this fails:

Rhino 1.7 release 2 2009 03 22
js> function A() {} A.prototype = { foo: "foo"}
[object Object]
js> function B() {}  B.prototype = { bar: "bar", __proto__ :
A.prototype }
[object Object]
js> c = new B
[object Object]
js> c.foo
js>

yet the following, which is equivalent works:

js> function A() {} A.prototype = { foo: "foo"}
[object Object]
js> function B() {}  B.prototype = { bar:
"bar"} ;B.prototype.__proto__ = A.prototype
[object Object]
js> c = new B
[object Object]
js> c.foo
foo
js>

I'd be curious to know why that is. Anybody have an explanation? (as
the top part works in Mozilla, but not in Rhino).

J




On Feb 16, 12:24 pm, John-Simon <[email protected]> wrote:
> I should note that the areas that use __prototype__ fail with
> __proto__ as well, which is where I'm wracking my brain.
>
> J:
>
> Rhino 1.7 release 2 2009 03 22
> js>  function A () {} A.prototype = { foo: "Quack" };
> [object Object]
> js> function B(){} B.prototype = { __proto__ : A.prototype, bar :
> "Foo" }
> [object Object]
> js> var foo = new B();
> js> foo instanceof A;
> false
> js>
>
> On Feb 16, 10:28 am, John-Simon <[email protected]> wrote:
>
>
>
> > I seem to be in a pickle on this one (from the Rhino shell):
>
> > js> function A() {
> >   > } A.prototype = { foo: "Quack", };
> > [object Object]
> > js> function B() {} B.prototype = { __prototype__: A.prototype, bar:
> > "Foo", };
> > [object Object]
> > js> foo = new B();
> > [object Object]
> > js> print (foo.bar);
> > Foo
> > js> print(foo.foo);
> > undefined
> > js> foo.__prototype__;
> > [object Object]
> > js> foo instanceof A;
> > false
>
> > Not quite sure what's going on here as this works in the Mozilla JS
> > engine (i.e. the browser). Can someone suggest a better way to perform
> > a.) inheritance and b.) making sure that things such as instanceof
> > work correctly?
>
> > Cheers,
>
> > JS

_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to