Javascript property listener

  • Thread starter Robert Mark Bram
  • Start date
R

Robert Mark Bram

Hi All,

I am writing a Javascript UI component. I have already written a
"disable()" method for it, but I would like to go one step further in
order to make my component as compatible with existing HTML controls as
possible.

With standard HTML controls we can do this:
myTextField.disabled = true;
and as soon as this property is set, I assume there is a property
listener of some kind that is invoked to change the appearance and
value etc of the control.

I want to write my own 'property listener' to do this with my control.
Can I do it in Javascript or is this too "low level", requiring code at
the browser implementation level?

Rob
:)
 
M

Martin Honnen

Robert Mark Bram wrote:

I want to write my own 'property listener' to do this with my control.
Can I do it in Javascript or is this too "low level", requiring code at
the browser implementation level?

Mozilla's JavaScript engine Spidermonkey allows you to set up setter and
getter functions for individual properties, here is an example:

var object = {
name: 'Kibo',
mDisabled: false
};
object.__defineSetter__(
'disabled',
function (value) {
// could execute any code here
return this.mDisabled = value;
}
);
object.__defineGetter__(
'disabled',
function () {
return this.mDisabled;
}
);

alert(object.disabled);
object.disabled = true;
alert(object.disabled);


But that is not standardized in ECMAScript edition 3, the current
standard the engines implement, and therefore for instance the JScript
engine used in IE or the engine used in Opera do not support that.

That is as far as engines go, in the browser there are some other
possibilities:

If you want to build GUI components in IE then you could look into HTCs
(HTML Components)
<http://msdn.microsoft.com/library/default.asp?url=/workshop/components/htc/reference/htcref.asp>
you can encapsulate your control there and also define properties:
<http://msdn.microsoft.com/library/d...omponents/htc/reference/elements/property.asp>

To build GUI components in Mozilla you can use XBL (XML binding language):
<http://developer.mozilla.org/en/docs/XBL>
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top