[...]
Dmitry that isn't only approach to "declare" local variable.
What exactly do you mean? The only way to declare variable is to use
`var` keyword. If to summarize points which could be related to
`variable` (regardless syntax rules such as `VariableStatement` -
12.2, ES-3) we can get the following:
(1) affecting on the VO/AO;
(2) created on entering execution context (main sign);
(3) get {DontDelete} attribute unless type of code is `eval`.
The point (1) is used to show that not every named object is affected
on VO/AO, e.g. named function expression (NFE) which by specification
should keep optional identifier in special object added in front of
scope chain but not in VO/AO itself; but as you know there're some non-
conformant impementations as some versions of JScript, including
current version.
The point (2) I suggest to use as a main sign to distinguish them from
the properties added to the special object of `with` statement and
`catch` clause. The two last will be available in the scope chain at
runtime, but not right after entering the execution context.
Moreover, regarding `with`, it doesn't declare that properties of its
special object should have {DontDelete} attributes, it depends on
object itself. So, in simple case we can delete this property:
with ({a: 10}) {
alert(typeof a); // number
delete a;
alert(typeof a); // undefined
}
But we can't if properties already have {DontDelete}
var a = 10;
with (this) {
alert(typeof a); // number
delete z; // error in JScript
alert(typeof a); // number, as `a` has {DontDelete}
}
From the other hand, not every variable declaration should get
{DontDelete} as it depends on type of code - in `eval` code they
shouldn't get {DontDelete}, so this point (3) is not the main.
But about point (2) regarding to execution context of function code
type, formal parameters also should get {DontDelete} depending on
code's type. So from this point of view formal parameters are the same
as variables - they created on entering execution context and should
have {DontDelete} depending on type of the code. But in difference
from variables, formal parameters get values (if corresponding values
are passed) also on entering the execution context, meanwhile variable
always get `undefined` on this step.
Regarding {DontDelete} and function's formal parameters, there's non-
conformant issue in Chrome - it doesn't set {DontDelete} in this case.
function test(a, b) {
alert([typeof a, typeof b]); // number, number
delete a;
delete arguments[1];
// undefined, undefined - in Chrome
// number, number - in other
alert([typeof a, typeof b]);
}
Also, regarding property of special object added by `catch` clause,
current version of Opera doesn't set {DontDelete} to it.
try {
trow 'error';
} catch (e) {
alert(typeof e); // string
delete e;
// undefined - in current Opera
// string - in other
alert(typeof e);
}
So, summarizing this all, variable is: added to the VO/AO on entering
the execution context (that differs it from other properties) and
_always_ has `undefined` value on this step (that differs it from the
formal parameter, which can have value any, but not only `undefined`
on this step).
What other approaches to "declare" local variable did you mean?
/ds