Subj : Re: JS_IsAssigning To : James Turner From : Brendan Eich Date : Fri Aug 29 2003 11:24 am James Turner wrote: >>Why do you need to detect a difference when resolving or getting 'bar' >>in foo between 'baz = foo.bar.x;' and 'foo.bar.x = 42;'? > > > Okay, this is going to take some explaining. Possibly, my basic design > is a bit wonky. > > In the example above, 'foo' is actually a JS object associated with a > native (C++) class called 'GameEntity'. One of the things the C++ > class defines is a map of property names to jsvals, and this acts as a > store for the various 'dynamic' (as opposed to hard-coded) props of > the gameEntity. [snip] > Okay, now someone comes to access the 'hairyness' of 'cat'. In > GameEntity's getter impl, the code essential does this: > > std::string propName = .... from the 'id' jsval ; > if (gameEntity->props.find(propName)) { > *rv = gameEntity->props[propName]; > } else { > // value wasn't locally set, use the default > *rv = gameEntity->archetpe->props[propName].defaultValue; > } > > This should hopefully reveal the problem. When the property type is an > object, and the value has not been locally set on the GameEntity, I > end up returning the defaultValue jsval, and then it gets modified - > not the desired result! Is the code above running for a get of foo.bar, or for a set of foo.bar.x? If a get of foo.bar, then I don't see how the default value of foo.bar will be modified by setting foo.bar.x = 42. I must be missing something. What I would like to do is determine if the > jsval I'm returning from my getter is going to be changed, and if so, > force it to be locally created on the GameEntity *before* I return it > from the getter. But setting foo.bar.x doesn't change foo.bar, so again (or still) I'm confused. /be .