Evertjan. wrote:
[snip]
"window" is the default and top element of the DOM tree.
In browsers, the window identifier is a reference to the global object.
The root of the document tree is the document object.
[snip]
"this" is the top element of the local DOM scope,
and that could be a <div>, an <a>, etc.
The this operator value is determined when entering an execution context
(normally, that means calling a function).
When executing "global" code:
<script type="text/javascript">
/* "global" code */
</script>
the this operator value is a reference to the global object.
this == window; // true
When calling a function as a method of some other object, the this
operator refers to that object:
var object = {
method : function() {
return this;
}
};
object.method() == object; // true
However, when a function is called directly, the this operator once
again refers to the global object:
var func = object.method;
func() == object; // false
func() == window; // true
Typically, event listeners are called by the browser as if they were a
method of the element. As a result, the this operator will refer to that
element. An exception is if the listener was added using MSIE's
attachEvent method; the this operator will refer to the global object.
>Also, is the "self" object the same as the "document" or "this" object?
"self" seems to be used outside the browser and DOM environment, ...
Perhaps, but it is also a property of the window (global) object, and is
a reference to the current window or frame.
[snip]
Mike