Any way to intercept object.property calls?

Hi

I'm not sure this is even possible, but I'm playing around with a specialized class and I would like to make it so undefined accesses are intercepted transparently to the user. For example, given object Foo which does not contain a "bar" property, I would like to have that access trigger some sort of "handleIfUndefined" method. It's easy enough to define a "get" method and always call that, but it would be kind of cool to be able to get this working.

Assume that object Foo doesn't currently have a "bill" property. What I would like to happen when a user does something like the following would be to silently initialize the "bill" record and return it rather than returning "undefined"

Some of the newer JavaScript engines support getters and setters, but for web development it's not practical right now because some of the major browsers don't support it and there is no way to even simulate it in those browsers.

edit: looks like I was mistaken, support for getters and setters appears to have been added to IE 9.

Some of the newer JavaScript engines support getters and setters, but for web development it's not practical right now because some of the major browsers don't support it and there is no way to even simulate it in those browsers.

edit: looks like I was mistaken, support for getters and setters appears to have been added to IE 9.

Getters and setters didn't work in this situation, because the property being accessed is undefined until the actual call is made. I think this would require a modification to the Javascript language itself, allowing for the definition of null methods, which could be called, as a last resort, before returning 'undefined'.

After playing around with this for several hours, I decided to just go with my 'getValue' method. Not quite as snazzy, but it does exactly what I want...