Peter,
I believe the primary purpose for this design is to preserve the
correct |this| for setters. For example:
p = {set a(value){ console.log(this.id) }, id: 1};
P = function(){};
P.prototype = p;
o = new P;
o.id = 2;
o.a = 3;
This should log the value 2 (not 1), and so basically the start
parameter is passed around with the put calls as
ScriptableObject.getProperty(obj,name) traverses the prototype chain
so if and when a setter is hit it can be called with the correct |
this|.
Kris

On Oct 8, 10:26 am, "Peter Michaux" <[EMAIL PROTECTED]> wrote:
> The documentation for Scriptable "put"
>
> http://www.mozilla.org/rhino/apidocs/org/mozilla/javascript/Scriptabl...)
>
> describes the second parameter "start"
>
> > Note that if a property a is defined in the prototype p
> > of an object o, then evaluating o.a = 23 will cause set
>
> What does "set" mean specifically? I don't think "set" is referring to
> some ECMA property that are usually in double brackets.
>
> > to be called on the prototype p with o as the start
> > parameter. To preserve JavaScript semantics, it is the
> > Scriptable object's responsibility to modify o.
>
> "the Scriptable object" refers to "o" or "p"? They could both be
> ScriptableObject instances, yes?
>
> I don't understand what the above is trying to say. To me, evaluating
> "o.a = 23" should set a value on "o" itself and not on o's prototype.
> If objects "n" and "o" both share the same prototype "p", then
> evaluating "o.a = 23" should not set the value "a" on prototype "p" as
> that would affect "n". I imagine that Rhino is doing the right thing
> but the above documentation seems misleading/confusing to me.
>
> > This design allows properties to be defined in prototypes
> > and implemented in terms of getters and setters of Java
> > values without consuming slots in each instance.
>
> Equally confused by this second paragraph.
>
> If someone explains what the documentation is trying to explain, I'll
> submit a documentation patch.
>
> Thanks,
> Peter

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

Reply via email to