This project is read-only.

Dynamic properties/methods?

Topics: Developer Forum, User Forum
Oct 19, 2011 at 10:12 PM

Is there any way to create an object for which the properties or are unknown at compile time? I think I've seen this in attempts to embed SpiderMonkey in other languages, so I imagine SpiderMonkey itself has this capability.

For example, I might have an .NET object which represents a database record in a table whose structure is unknown at compile time. At runtime, when the script attempts to retrieve a variable from the object, my code would have a chance to look for a field in that record that matches that variable name, read the data from that field, and return it. If the field is not found, it would be able to return undefined, as if it were a property that hadn't been declared.  This would allow a programmer writing a plugin for my software to use the experssion 'Order.quantity' instead of 'Order.getFieldValue("quantity")'.

Oct 28, 2011 at 8:20 AM

So like a lookup property hook?

Oct 28, 2011 at 10:25 AM

take a look at this svn commit and tell me if this is basically what you had in mind
http://spidermonkeydotnet.codeplex.com/SourceControl/changeset/changes/93857

Oct 30, 2011 at 7:15 PM

If the DynamicObject.cs is an example of how I would use this, then that is exactly what I had in mind.

Unfortunately, my project went in a completely different direction soon after I made the original post, so I won't be using sm.net. But, it's good to know this will be there if we need this for another project.