function invocation in response to a property assignment

Discussion in 'Javascript' started by kristoph@gmail.com, Feb 17, 2007.

  1. Guest

    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, 2007
    #1
    1. Advertising

  2. 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/
    Martin Honnen, Feb 17, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Calvin Lai
    Replies:
    6
    Views:
    20,820
    Joerg Jooss
    Dec 31, 2003
  2. Function invocation location

    , Dec 22, 2005, in forum: C Programming
    Replies:
    15
    Views:
    578
  3. Replies:
    18
    Views:
    549
    Kenny McCormack
    Jan 17, 2007
  4. Poor Yorick
    Replies:
    2
    Views:
    291
    Bruno Desthuilliers
    Jul 13, 2007
  5. Peter Olcott
    Replies:
    5
    Views:
    410
    Peter Olcott
    Aug 17, 2008
Loading...

Share This Page