function invocation in response to a property assignment

K

kristoph

Greetings,

I would like to be able to take some action (implemented in a
function) when a property is assigned a new value (much a page is re-
rendered when, for example, a style is changed).

So if I do ...

myObject.myProperty = 5;

I want myObject.myFunction to be called.

Is this possible at all?

Thank you,

]{
 
M

Martin Honnen

So if I do ...

myObject.myProperty = 5;

I want myObject.myFunction to be called.

Is this possible at all?

Mozilla/Netscape implement getter/setter function for properties e.g.

var object = { _myProperty: undefined };
object.__defineGetter__('myProperty',
function () { return this._myProperty; });
object.__defineSetter__('myProperty',
function (value) { return this._myProperty = value; });

object.myProperty = 'Kibo';

alert(object.myProperty = 'Xibo');

The getter function (anonymous above) is being called when myProperty is
read, the setter function (also anonymous) is called when myProperty is
being assigned to.

But the script engines in browsers like IE or Opera do not support
getter/setter function that way so on the web in general you don't have
that mechanism available.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top