A
aum
Hi,
Does Javascript have any equivalent to Python's __getattr__ and
__setattr__ methods?
In other words, the option to define a method of a class that gets invoked
whenever someone tries to fetch an unknown attribute, or set any attribute
of an instance of that class?
I've looked at __defineGetter__, __defineSetter__, __lookupGetter__ and
__lookupSetter__. It did seem like __lookupGetter__ and __lookupSetter__
might have been helpful, but they only seem to return methods that have
already been set with __defineGetter__ and __defineSetter__.
I need a way for an object to invoke a method when any attempt is being
made to fetch an attribute of that object (or, similar to Python, to fetch
an unknown attribute).
Cheers
aum
Does Javascript have any equivalent to Python's __getattr__ and
__setattr__ methods?
In other words, the option to define a method of a class that gets invoked
whenever someone tries to fetch an unknown attribute, or set any attribute
of an instance of that class?
I've looked at __defineGetter__, __defineSetter__, __lookupGetter__ and
__lookupSetter__. It did seem like __lookupGetter__ and __lookupSetter__
might have been helpful, but they only seem to return methods that have
already been set with __defineGetter__ and __defineSetter__.
I need a way for an object to invoke a method when any attempt is being
made to fetch an attribute of that object (or, similar to Python, to fetch
an unknown attribute).
Cheers
aum