defineSetter Method

New for Windows Internet Explorer 8

[This documentation is preliminary and is subject to change.]

Allows developers to create new or override existing Document Object Model (DOM) properties and functions using functionality implemented by a custom Microsoft JScript function. The custom function is used to set the value of a property or a function.

Syntax

object.defineSetter(propname, pdispHandler)

Parameters

propname Required. Name of the property or function to be modified.
pdispHandler Required. Name of the JScript function that provides the new functionality.

Return Value

No return value.

Remarks

The name of the method is preceded and followed by two underscore characters (__).

The defineSetter method can be used to override DOM properties, DOM functions, and expandos. You cannot use defineSetter to override JScript objects or functions.

When defined for built-in properties or functions, defineSetter overrides the built-in property or function. When referring to functions that support arguments, include required arguments in the call to defineSetter.

Use the delete operator to delete custom properties or functions created using defineSetter and to restore overridden properties or functions to their original functionality.

To cache (save) a function to be overriden with defineSetter, assign the function to a variable before overriding it. To invoke behavior cached to a variable, use the apply method or the call method.

The defineSetter is only supported in IE8 mode. For more information, see Defining Document Compatibility.

Warning   This feature is not yet standardized and the current implementation is based on similar features in other web browsers. Should the final standard specify an alternate implementation, the current implementation may change.

Example

This example shows how to create a write only property, a property that cannot be read.

try
{
  document.__defineSetter__("writeOnlyProp", function(value)
  {
    alert("write only: " + value);
  }
} catch(e)
  { alert( "setter not supported: " + e.message); }

// Displays "to-write" in IE8 and "undefined"
// in earlier versions.
document.writeOnlyProp = "to-write";
alert( document.readOnlyProp );

Applies To

style, rule, currentStyle, attribute, TextNode, attributes, StaticNodeList, children, defaults, HTMLGenericElement, styleSheet, HTMLLinkElement, HTMLFormElement, HTMLTextElement, IMG, XMLHttpRequest, BODY, FONT, A, LABEL, UL, OL, LI, BLOCKQUOTE, DIV, DD, DT, BR, DL, HR, P, elements, hn, SELECT, OPTION, INPUT, TEXTAREA, BUTTON, MARQUEE, HTML, HEAD, TITLE, META, BASE, ISINDEX, nextID, BASEFONT, event, screen, window, DocumentCompatibleInfo, documentCompatibleInfoCollection, document, EMBED, areas, MAP, AREA, CAPTION, COMMENT, INS, DEL, SPAN, TABLE, COL, TBODY, TFOOT, THEAD, TR, TD, SCRIPT, NOSCRIPT, OBJECT, PARAM, FRAME, IFRAME, FIELDSET, LEGEND, FRAMESET, BGSOUND, STYLE, XDomainRequest, Storage

See Also

defineGetter, lookupGetter, lookupSetter