Hello,

I want to have objects in my app that behave like arrays. So far I have 
tried implementing the array-like functionality on a base "Component" 
object using the SetIndexedPropertyHandler() method. While this does work 
great for the Component object - it does not for any other objects that 
inherit (via prototype chain).

So:

var parent = new Component;
// parent[4] <-- works

function Child {}
Child.prototype = new Component;
var child = new Child;
// child[4] <-- will not fire IndexedPropertyHandler events

Is there a quick and easy solution to this issue? Or it's by design?

As a workaround I figured since all my Component objects are assigned 
(registered) to a special property at some point - I can dynamically wrap 
fake constructors around it (intercepting assignments 
with SetNamedPropertyHandler to a global "components" object). So the 
result was:

Handle<Object> comp = Handle<Object>::Cast(/* simple JavaScript { value: 
"123" } object */);
Handle<FunctionTemplate> compTemplate = FunctionTemplate::New();

// Add indexed property handlers
compTemplate->InstanceTemplate()->SetIndexedPropertyHandler(...);

Handle<Function> compConstructor = compTemplate->GetFunction();
compConstructor->SetPrototype(comp); // This seems to have no effect?

// .. and the code that assigns the compConstructor to global "components" 
via ForceSet()

Then every time I assign a new object to some property, like this:

components.Test = { value: "123" }

I can then construct a new component object:

var test = new components.Test();

But that new object will not inherit the "value" via prototype chain. I 
can't wrap around my head why the line 
"compConstructor->SetPrototype(comp)" does not work? Any help 
is appreciated.

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to