Subj : Re: Properties and Objects To : Joseph Smith From : Brendan Eich Date : Thu Nov 20 2003 01:27 pm Joseph Smith wrote: >Hello, > >I am trying to figure out how to use properties properly in javascript >using mozilla embedded into my application, and am currently quite >stumped. > >What i would like to be able to do from script would be to call >somthing like the following: > >Map.Entity("Name").Leg(BONES_LEG_LEFT_THIGH).Move(x,y,z,distance); > > Do you really want Entity and Leg to be methods (function valued properties), or would you rather they be arrays? Either way, you can dynamically compute results of "indexing" into these collections. It's mostly a matter of style, and I say good JS style prefers arrays and [] subscripting to method calls. >How would one go about passing in an object type with a search >parameter like a name (deliminated by a string), and then calling >properties and methods of that object? > > For your example, define function-valued properties, AKA methods, in each object, going from left to right. Each method call returns the next object in the chain, which is of a class that supports the next method call. See JS_InitClass in particular, and all the docs under http://www.mozilla.org/js/spidermonkey. Have you read the embedding tutorial, looked at js.c, read through the (still too bogus, but getting better) API docs? /be .