Hi,
Rhino supports the __define[GS]etter__ as in SpiderMonkey, which is
great! However, it doesn't work on arrays (even though it does work on
SM):
js> a = [1,2,3]
js> a.__defineGetter__(1, function() { print("masked!"); });
js> a[1]
2
This is somewhat understandable as arrays indexing has a few more
specificities when compared to regular properties. However I think
this is still an interesting feature.
My specific use case is that I need to proxy an array so that all
values are loaded only on access from some backend. However I believe
there's a whole array (pun intended) of use cases where this feature
would be valuable, in the same way that __define[GS]etter__ is
valuable.
I've started implementing this in Rhino and it's actually not such a
big change. I'd be happy to contribute it (just need to implement the
lookup methods as well) but would like to know your opinion before.
Would you accept this modification to Rhino?
An extension to this (which I don't believe exists in SM) could be,
mostly for performance reasons, to support something like:
a.__defineGetter__('[]', function() { print "masked!"; });
This would override all index accessors, whatever the index. For large
arrays it would be much better as you only have a single function
definition.
So what do you think about this little proposal?
Thanks,
Matthieu
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino