VK said:
It is not true at least for IE 5.0 or higher and Opera 8.0
or higher - thus for 80%-90% of the browsers on the market
(grace to IE).
What is not true? That - window.setTimeout - should take longer to
resolve than unqualified - setTimeout -? It does take longer, you just
have to time it to see that.
Therefore ECMA-compliant scope schema will be rather a rare
exeption than a rule with your visitors. One can hate it,
scream and cry about it
- but at least she should be
aware of it.
So is it the resolution of Identifiers against the scope chain, or the
scope chain itself that you think does not follow the specification?
That should be fairly simple to demonstrate as all you would have to do
is show some code that ECMA 262 says should result in one behaviour that
actually exhibits another. Of course you need to both know what ECMA 262
says the code should do and understand the code written. That is a bit
of a problem for you as you don't understand ECMA 262 or the javascript
you write.
For IE and Opera "Global" object and "window" object
constitute two distinct programming scopes.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
And that should be a fairly simple assertion to back-up. Although
"programming scopes" is essentially meaningless; another piece of
fictitious jargon from someone more interested in giving the impression
that they know more than they do. On the other hand "two distinct" is
concrete enough for consideration. It implies that the global object and
the window object are two distinct entities.
Again I'm not talking about some
occasional models like Adobe SVG plugin or such.
I'm talking about the standard environment of a HTML page
(XHTML is not supported by IE and interpreted as regular HTML)
with a script running on it.
In such case we have Global scope (level of global variables
ang Global methods like escape, encodeURI etc.) and Window scope
*above* it (level of ID'entified HTML elements and window methods
like setTimeout, open etc.)
The implication if which is that there are two distinct objects on the
scope chain; one the ECMAScript global object with the specification
defined properties and the other a true host object with browser defined
properties.
On lookup the engine search first in the Global scope, if not
found then in the window scope.
So in scope chain resolution the ECMAScript global object is encountered
first on the scope chain and the 'window' object comes after that?
Well, we can test that proposition with a bit of scope chain
augmentation. Suppose we explicitly put the object referred to by -
window - on the scope chain of an inner function (with a - with -
statement) and give the outer function local variables with identifiers
that would mask global properties of interest. Acting upon those
unqualified Identifiers inside the inner function would not involve the
consequences of getting to the end of the scope chain because if not
resolved as propitious of the object added to the scope chain they would
be caught by being resolved as priorities of the Activation/variable
object of the outer function.
If the window and global objects are two distinct entities that have
different sets of properties, Identifiers referring to properties of
the one that had _not_ been added to the scope chain would be
resolved as the outer function's local variables. Finding any single
Identifier that could not be resolved as a property of the object
added to the scope chain would _prove_ that there were two distinct
objects, failing to demonstrate this would suggest a single global
object. E.G:-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"
http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script type="text/javascript">
var globalVar = 'Global Variable';
function getWindow(){
return window;
}
function getGlobal(){
return this;
}
window.onload = (function(){
var localFnc;
/* Identifier corresponding with IDed DIV element */
var testDiv = 'Outer Function variable';
/* Identifiers corresponding with ECMA global object properties */
var Math = 'Outer Function variable';
var Array = 'Outer Function variable';
var Object = 'Outer Function variable';
var eval = 'Outer Function variable';
/* Identifiers corresponding with browser object model global
properties. */
var clipboardData = 'Outer Function variable';
var setTimeout = 'Outer Function variable';
var alert = 'Outer Function variable';
var window = 'Outer Function variable';
/* Identifier corresponding with a declared global variable */
var globalVar = 'Outer Function variable';
/* Explicitly add a property to the - window - object:- */
getWindow()['foo'] = 'Assigned to window object'
/* Identifier corresponding with an property explicitly added
to the window object */
var foo = 'Outer Function variable';
/* Explicitly add a property to the - this - object:- */
this['bar'] = 'Assigned to window object'
/* Identifier corresponding with an property explicitly added
to the window object */
var bar = 'Outer Function variable';
/* Cannot use the - window - reference directly as it is defined
as a local string variable in this scope so call a function
that will return - window - instead:- */
with( getWindow() ){ // Add the - window - object to the inner
// function's scope chain.
localFnc = (function(){
alert(
'*Identifier corresponding with IDed DIV element\n'+
'testDiv = '+testDiv+
'\n\n*Identifiers corresponding with ECMA global object'+
' properties\n'+
'\nMath = '+Math+
'\nArray = '+Array+
'\nObject = '+Object+
'\neval = '+eval+
'\n\n*Identifiers corresponding with browser object model'+
' global properties.\n'+
'\nclipboardData = '+clipboardData+
'\nsetTimout = '+setTimeout+
'\nalert = '+alert+
'\nwindow = '+window+
'\n\n*Identifier corresponding with a declared global'+
' variable\n'+
'\nglobalVar = '+globalVar+
'\n\n*Identifier corresponding with an property explicitly'+
' added to the window object'+
'\nfoo = '+foo+
'\n\n*Identifier corresponding with an property explicitly'+
' added to the global - this - object'+
'\nbar = '+bar+
''
);
});
}
/* Return the inner function so it can be assigned to
- window.onload -:- */
return localFnc;
})();
</script>
</head>
<body>
<div id="testDiv">XXX</div>
</body>
</html>
It is also possible to repeat that experiment using the - this -
reference as the object added to the scope chain (or any other
candidate for similar consideration).
And the results of running that on IE 6 are that whichever object (-
window - or - this -) is added to the inner function's scope chain that
object has; properties that correspond with IDed DOM elements,
properties that correspond with ECMA 262 defined global properties,
properties that correspond with expected browser object model global
properties, properties that correspond with declared global variables
and properties corresponding with properties added to both the -
window - and - this - object at runtime.
This result shows no evidence of two distinct objects at the end of the
scope chain as the single object that is expected to be at the end of
the scope chain behaves as if it has all the required properties itself.
Therefore if we say declare
var setTimeout = 'foobar';
we shadow window.setTimeout reference (engine will find
"setTimeout" in the Global scope first thus will never
look in the window scope above).
No demonstration of 'shadowing' has been made. The behaviour
demonstrated is instead completely in accordance with a single global
object being subject to procedure for variable instantiation as
described in ECMA 262, 3rd ed. sections 10.1.3 and 10.2.1.
Respectively if we declare:
window['foo'] = 'bar';
and later call alert(foo) then engine will look first in
the Global scope, fail on it, then look in
the window scope and find it.
With the implication that the global object does not have an - alert -
property or a - foo - property? Neither have been demonstrated, and the
above test shows that both the - window - object and the global - this -
object behave in isolation as if they have properties corresponding with
ECMA 262 defined global properties, browser global properties, declared
local variables, runtime added properties, etc.
For a non-aware user the fact that:
window['foo'] = 'bar';
alert(foo); // 'bar'
may lead to the conclusion that Global scope and window scope
are the same - but nothing more far from the true than that,
again - at least for IE and Opera.
So far no case has been made for that conclusion.
It also explain the real mechanics of possible circular
reference leaks in IE
You mean the things that you didn't believe existed last week, and still
don't understand?
as well as explains the overall higher memory consumption
by JScript - which is *not* a memory leak but makes nervious
many developers, specially ones coming from a C++ or so
background.
Explaining the circular reference memory leaks in terms of inaccessible
additional objects in the scope chain would be inadequate as then the
problem could not be addressed, due to the inaccessibility of these
additional objects.
As I'm kind of tired of regular hysterics about
"VK unbellyfeels ECMA":
Stop making out that you know something special to people who have a
better understanding of the subject than you and have considerably
greater talent for analysis than you and you may stop people calling you
a fool.
here a sample and I don't care if it trigs the thinking
process or the doublethink will help as usual.
Although writing sentences that make sense would also contribute to your
not being considered quite the fool you currently are.
...
<script type="text/javascript">
Once again you post code without stating what it is you suppose that it
is demonstrating. And in not stating what is supposed to be demonstrated
by this code it becomes difficult to say whether it is demonstrated or
not, but presumably if you are trying to make any point at all your
notion of this code is that it demonstrates something that would differ
from the behaviour predicted by an ECMA 262 conforming implementation.
Well, lets look at the ECMA 262 derived perdition and see if the results
do demonstrate IE differing from that behaviour:-
A global variable is declare and assigned a value. Variable
instantiation in the global scope uses the ECMAScript global object as
the variable object so it would be the global object to which a property
would be added with the name 'v1', unless the property already exists in
which case it is left alone. When the global code is executed a value is
assigned to that property of the global object.
function demo() {
var v2 = true;
A local variable is created with the name 'v2' on the function's
execution context's Activation/variable object and when the function
body is executed the boolean value - true - is assigned to that
property.
Output, now we get to see if behaviour corresponds with expectations.
The Identifier - alert - is resolved into a reference to the global -
alert - function and that function is called with an argument list
consisting of the value read using the Identifier - v1 - . The
Identifier - v1 - is resolved at the end of the scope chain as a
property of the global object that corresponds with the declared global
variable and has the value - true -. The - alert - function
type-converts its boolean - true - argument into the string 'true' and
alerts that.
ECMA 262 predicted outcome: alters the string 'true'.
Observed outcome: alerts the string 'true'.
Similarly the Identifier - v2 - is resolved as a property of the
function's execution context's Activation/Variable object. That property
has the value - true - and alert type converts that into the string
'true'.
ECMA 262 predicted outcome: alters the string 'true'.
Observed outcome: alerts the string 'true'.
This time the argument to - alert - is the result of the expression -
this[v2] -. As this function is executed as a method of the - window -
object the - this - keyword is resolved as a reference to the - window -
object. The bracket notation property accessor requires that the - v2 -
Identifier be resolved, evaluated and type-converted into a string that
will be used as a property name in association with the - this - object.
The - v2 - Identifier is resolved as the local variable - v2 - with the
value - true -. That value is type-converted into the string 'true' and
used as the property name to be resolved in association with - this -,
i.e.- this['true'] -.
The expression - this['true'] - returns the value - undefined - because
the window object has no property named 'true', and alert type-converts
undefined into the string 'undefined' and alerts that.
ECMA 262 predicted outcome: alters the string 'undefined'.
Observed outcome: alerts the string 'undefined'.
As we know IE (and other browsers) make DOM elements with ID attributes
available as global properties under names corresponding with their IDs,
assuming that they do not clash with declared global variables. The
Identifier - v3 - corresponds with the ID of a DOM element and does not
clash with a declared global variable so we can expect - v3 - to resolve
as a reference to that DOM element. The type-conversion of an IE DOM
element to a string is the string '[object]' so that is what will be
alerted.
ECMA 262 predicted outcome: alters the string '[object]'.
Observed outcome: alerts the string '[object]'.
}
window.onload = demo;
</script>
...
<div id="v1">v1</div>
<div id="v2">v2</div>
<div id="v3">v3</div>
...
So once again you post code that is supposed to demonstrate some arcane
'truth' that actually does no more than behave 100% in accordance with
the behaviour that would be expected of a 100% ECMA 262 3rd ed.
conforming implementation. There is certainly nothing happening here
that requires more than one global object, or suggests any additional
objects on the scope chain.
Did you, by any chance, let yourself be fooled by - alert(this[v2]); -
alerting ' undefined'? I think you did, but as has been pointed out so
many times you don't understand the basics of javascript so you don't
understand what the code you write actually does. You probably indented
to write - alert(this['v2']); - or - alert(this.v2); -, but that would
have alerted '[object]' and done nothing but demonstrated more expected
behaviour.
P.S. If it helped to start the thinking process (which
I still hope despite don't care too much anymore):-
It appears that no matter how often you make yourself look a fool in
public it never starts your thinking process. You have made the mistake
of confusing yourself with someone who knows what they are doing and
apparently no amount of evidence to the contrary is capable of enabling
you to rectify that error.
the next question would be: "Is it possible and how in IE's
scope model that a DOM object is still referenced in the
execution context - thus not GC-available - despite
no one JScript variable holds a reference to it?"
Given that you made your original proposition up off the top of your
head without any evidence to back it up and posted a non-demonstration
of it 'in action', the 'next question' is entirely moot. However, that
'next question' hardly qualifies as a question, being the sort of
incoherent rambling that might be expected from the mentally ill.
Richard.