jurassic
jurassic copied to clipboard
Question about custom indexer
trafficstars
Can I expose object's indexer with string key?
Say, I implemented the class:
class ClrObjectInstance : ObjectInstance
{
//... ctor and other things here
public object this[string name]
{
get => "hello";
set {}//do something here
}
}
and I want to the indexer be called when somewhere in JS the following code executed:
customObject['zoom'] = 1;
FYI in javascript customObject['zoom'] = 1; is the same as customObject['zoom'] = 1.
Unfortunately, if you write an indexer like that, it won't get called. You can override GetMissingPropertyValue to implement the getter, but I can't think of an easy way to do the setter off the top of my head.