469,336 Members | 6,002 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

function invocation in response to a property assignment

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,

]{

Feb 17 '07 #1
1 1108
kr******@gmail.com wrote:
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.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 17 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Nitin | last post: by
19 posts views Thread by Gary Kahrau | last post: by
41 posts views Thread by Telmo Costa | last post: by
36 posts views Thread by danielx | last post: by
7 posts views Thread by Darko | last post: by
1 post views Thread by Mike | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.