defineGetter method

Obsolete. Do not use.

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 return a value from a property or function.

 

Syntax

HRESULT retVal = object.defineGetter(propname, pdispHandler);

Parameters

  • propname [in]
    Type: BSTR

    Name of the property or function to be modified.

  • pdispHandler [in]
    Type: IDispatch

    Name of the JScript function that provides the new functionality.

Return value

Type: HRESULT

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Remarks

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

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

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

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

To cache (save) a function to be overriden with IHTMLDOMConstructor::DefineGetter, 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 IHTMLDOMConstructor::DefineGetter is only supported in IE8 Standards 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.

 

Examples

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

try
{
  document.__defineGetter__("readOnlyProp", function()
  {
    return "read only";
  }
} catch(e)
  { alert( "getter not supported: " + e.message); }

// Displays "read only" in IE8 and "undefined"
// in earlier versions.
alert( document.readOnlyProp );

try
{
  // The next line generates a script error in IE8
  document.readOnlyProp = "value"; 

  // In IE7, the next line displays "value"
  alert(document.readOnlyProp);
} catch(e)
  { alert( "Sorry, this property cannot be changed." ); }

See also

style

rule

currentStyle

attribute

TextNode

attributes

IHTMLDOMConstructorCollection::StaticNodeList

children

defaults

IHTMLDOMConstructorCollection::HTMLGenericElement

styleSheet

IHTMLDOMConstructorCollection::HTMLLinkElement

IHTMLDOMConstructorCollection::HTMLFormElement

IHTMLDOMConstructorCollection::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

Reference

IHTMLDOMConstructor::DefineSetter

IHTMLDOMConstructor::LookupGetter

IHTMLDOMConstructor::LookupSetter