Re: jslint doesn't like my syntax for conditional object creation



Richard Cornford wrote:
VariableDeclaration productions
are processed during 'variable instantiation' (ECMA 262, 3rd ed.
Section 10.1.3) to create properties of the Variable object, prior to
the execution of code for the execution context. So the creation of
such properties of the Variable object cannot be influenced by control
flow inside the code as it has not been executed at the point of
'variable instantiation'.

OK, I admit you got me on this one - I was wrong (and ECMA specs amused
me once again).

For me the "variable declaration" is strictly like:

var a = null;
var b = '';
var ...
....
// program flow
....

and that was the point I was arguing (that the variable Serious was not
explicetly pre-declared). It did not cross my mind of this hack with
the parser fetching all var operators and pre-declaring them.

So presuming that
if (Serious == null) { var Serious = {}; }

is used outside of any function, this trick does work and it doesn't
lead to the exception. (Within a function such check is useless as
local Serious will be always here with value undefined).

I guess we can adjust the mutual score (your var operator pre-fetching
against my script tag usage :-)

But why did you decide to account this trick in the JSLint? I thought
it was supposed to be a code validator and cleaner, not a curiosity
store? Why did you decide to teach your users that if they are smart
and careful enough, they can avoid pre-declaring variables in their
code?

.



Relevant Pages

  • Re: Functional question
    ... The variable declaration happens just after function declarations have ... The assignment only happens when the execution of the body reaches ... | added as properties of the variable object. ... Your function ggets then overwritten by var g. ...
    (comp.lang.javascript)
  • Re: variable instantiation & eval
    ... The specification of the var statement says: ... One could read it that way in isolation, but taken with section 10.2.3, where for "Function code" it says "Variable instantiation is performed using the activation object as the variable object and using property attributes {DontDelete}", it would be difficult to sustains the "only". ...
    (comp.lang.javascript)
  • Re: tuning stored procedure, variables and different optimisers
    ... available to the optimizer at compile time ... declare @var int ... execution time (since the whole batch is compiled at once, ...
    (comp.databases.ms-sqlserver)
  • Re: jslint doesnt like my syntax for conditional object creation
    ... Section 10.1.3) to create properties of the Variable object, ... the execution of code for the execution context. ... javascript _before_ trying to give advice to others on the subject. ... never even grasped the basics of javascript but is so deluded that you ...
    (comp.lang.javascript)
  • Re: setTimeout and an objects methods
    ... instance property at the time of its execution. ... There is also the question of how often - trigger - will be called. ... var f1 = new Foo; ... What is also happening is that a closure is formed by the ...
    (comp.lang.javascript)