2.7.2 Event Handler Function Definitions

The extensions described in this section are not available in EdgeHTML Mode.

Internet Explorer ECMAScript adds an additional alternative to the FunctionDeclaration grammar production of [ECMA-262/5], section 13, as follows:

Syntax Extension

FunctionDeclaration :

function Identifier ( FormalParameterListopt ) { FunctionBody }

function ObjectPath :: Identifier ( FormalParameterListopt ) { FunctionBody }

ObjectPath :

Identifier

ObjectPath NameQualifier Identifier

NameQualifier : .

Semantic Extensions

Internet Explorer ECMAScript allows a FunctionDeclaration element to be evaluated as a Statement production, as follows:

FunctionDeclaration : function ObjectPath :: Identifier ( FormalParameterListopt ) { FunctionBody }

When this production is evaluated, the following steps are performed:

  1. Let p be the result of the evaluation of ObjectPath.

  2. Let o be ToObject(GetValue(p)).

  3. If o is not a host object that supports event attachment, throw a TypeError exception.

  4. Let eventName be a string that contains the text of Identifier.

  5. Let h be the result of creating a new Function object, as specified in [ECMA-262/5], section 13.2, with the parameters specified by FormalParameterListopt and the body specified by FunctionBody.

    1. Pass in the VariableEnvironment component of the running execution context as the Scope.

    2. Pass in a value of true as the Strict flag if the FunctionDeclaration element is contained in strict code or if its FunctionBody element is strict code.

  6. Perform event handler attachment of h to o by using eventName as the event name.

  7. Return (normal, empty, empty).

An event handler function h is attached to a host object o with eventName n as follows:

  1. If o implements the IBindEventHandler COM interface (http://msdn.microsoft.com/en-us/library/56zc7scb(VS.85).aspx), perform the following actions:

    1. Call the BindHandler COM method of o, passing arguments n and the function entry point h. This call hooks up the direct event.

    2. Return.

  2. If o does not implement the IBindEventHandler COM interface, retain the information (o, n, and h), and defer the event binding until the script engine is placed into "connected" mode, as defined by the SCRIPTSTATE_CONNECTED constant value of the Microsoft Windows Script Technologies SCRIPTSTATE enumeration (http://msdn.microsoft.com/en-us/library/f7z7cxxa(VS.85).aspx). When the script engine is placed into the connected mode, the retained information is used to bind the event with an event sinking process. The event binding is performed immediately if the script is already in connected mode.

  3. Return.

The IConnectionPointContainer COM interface (http://msdn.microsoft.com/en-us/library/ms683857(VS.85).aspx) is used to perform the event binding in step 2, regardless of whether the binding is performed immediately or is deferred.