Subj : Re: Properties and Objects To : Joseph Smith From : Brendan Eich Date : Sat Nov 29 2003 09:46 am Joseph Smith wrote: > I may have confused you with the notation of above line, but i meant > that Entity("Name") would call Map.Entity and pass in a string, which > i could use to select a given entity from the map, where as i was > thinking along the lines of an Enum (or global const properties for > the BONES_LEG_LEFT_THIGH) etc for the leg object (ie > Leg(BONES_LEG_RIGHT_THIGH) instead of LEFT) :) Notation aside (my comment was that [] is the more natural operator to use here, in JS, Java, C++, or other C-based languages, not the () or "call" operator), I understood what you meant. If you insist on using () instead of [], you won't be able to use the usual JSClass hooks (getProperty, setProperty). You'll have to implement each successive object in the chain as a callable object (implement JSClass.call). If you want users to be able to assign to an expression such as foo.bar(i), you'll need to use JS_SetCallReturnValue2. > Can you point me anywhere relevant to this sort of use of > spidermonkey??? Did you look at the docs under http://www.mozilla.org/js/spidermonkey/ ? http://www.mozilla.org/js/spidermonkey/tutorial.html is a start, but it doesn't say how to create an object and give it a name (JS_DefineObject). If you read http://lxr.mozilla.org/mozilla/source/js/src/README.html next, you will learn about JS_DefineObject. Beware that this doc needs to be updated to say "call JS_ShutDown(); after all other API calls, when tearing down the runtime and finishing using the JS API." I'll fix that now. So with the runtime, context, and global object setup and teardown you can learn from these docs, and with JS_DefineObject, you can create a situation where "Map" names an object whose class you implement. Then you will want to study JS_InitClass, so you can create Entity, Leg, and other classes that have custom properties. Each class can have predefined properties in its prototype object, shared by all instances. You can also resolve names on-the-fly, for lazy reflection of properties that you can't or won't predefine. Hope this helps. /be .