You are here: Re: [PHP] JavaScript - object property « PHP « IT news, forums, messages
Re: [PHP] JavaScript - object property

Posted by Richard Lynch on 10/20/11 11:14

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация