Re: JavaScript - object property

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, April 26, 2005 7:51 pm, Eli said:
> I know this is not the forum, but I googled and couldn't find it, so
> please try to help me with this.
>
> /*********/
> function MyCls(name)
> {
>     this.name=name;
> }
> function SayHi()
> {
>     alert('Hi, '+this.name+'!');
> }
> var obj=new MyCls('PHP');
> obj.name='JavaScript';  //this will call SayHi() function
> /*********/
>
> I have a class in JS with a property variable in it. How can I execute a
> function when the property value is changed?

I don't think JavaScript has any way to hook into a property being changed
and take some action on that...

It *MIGHT* have 'private' properties, that can't be changed by child
classes, and then you'd have to use a function to change the property, and
then your function that changes the property can do whatever it wants...

But that all assumes JavaScript even has "private" properties, which it
may not have.

Your only other option is to just DOCUMENT that nobody should ever alter
".name" directly, but should always use your changeName() function which
does whatever you want it to do.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux