Re: undefined vs. undefined (was: new Array() vs [])



VK wrote:
(see the post by ASM in the original thread; can be seen at

<http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3
716384d8bfa1b0b>
as an option)

As that is not in relevance to "new Array() vs []" question
or to the array performance, I dared to move it to a new thread.

Or was it because you might avoid looking as much of a fool if you post
this without a context as you would if you did.

Gecko takes undefined value strictly as per Book 4, Chapter 3,
Song 9 of Books of ECMA
:-)
(Paragraph 4.3.9 of ECMAScript Language Specification, 3rd edition)
:-|

The numbering of clauses in ECMA 262 has no relationship to paragraphs,
books, chapters or songs.

<quote> The undefined value is a primitive value used when
a variable has not been assigned a value. </quote>

And section 10.1.3 explains the assignment of the undefined value to
instantiated variables. And no observable behaviour of _any_ ECMAScript
implementations contradicts section 10.1.3.

As a matter complication JavaScript is the only language I
know where one can write:
var foo = undefined;

The only thing specific to javascript in that statement is using - var -
to declare a variable (and that may not be unique to javascript).

which is - strictly speaking - "keep foo but assign it the
value that foo was not assigned and never existed"

Nonsense. The meaning of that statement is in two parts:-

1. During 'variable instantiation' for the execution context; create
a property named 'foo' on the Activation/Variable object for the
execution context (with a DontDelete attribute) and assign the
Undefined value to it.

2. When execution of the code arrives at the assignment expression:
The left-hand side is evaluated (into a Reference type with
the Activation/Variable object as its 'base' property and 'foo'
as its property name). The right hand side is evaluated to a
value:
The Identifier 'undefined' is resolved against the scope chain
to give a Reference type. ECMAScript Edition 3 introduced a
property of the global object with the name 'undefined' set to
the Undefined value so the Reference type will likely have the
global object as its 'base' property. In pre-ECMAScript edition
3 environments that do not have a global 'undefined' property
as an extension, or no programmer defined alternative has been
created, the 'base' property of the Reference type will be null.

The resulting Reference type is then passed to the internal
GetValue function to recover a value (and exception will be
thrown at this point if the Reference type has a null 'base'
property).

The value of the right hand side is then used with the Reference
type from the left hand side in order to assign the value. The
property of the Activation/Variable object named 'foo' is
assigned the value of the right hand side (assuming no exception
was thrown while recovering the value from the Identifier
- undefined -).

which is - even more strictly
speaking - totally meaningless.

What you wrote is meaningless, but that is just a manifestation of your
not understanding javascript. The actual statement is doing nor more
than (and no less than) evaluating a variable (undefined) and assigning
its value to another variable (foo).

In case of an elision in an array initializer you *do* assign
values to each and every array member

Rubbish. The evaluation of an elision will not result in any value being
assigned to any element of an array except its - length - property in
the event that the elision is not followed by an AssignmentExpression.

(Mr. Cornford would say something like
"[[Put]] method is called for each evaluation result").

I am unlikely to say something that is utterly false.

This way
var arr = ['A',,'B']
really means
var arr = ['A',undefined,'B']

No it does not. It is closer to:-

var arr = new Array;
arr[0] = 'A';;
arr[2] = 'B';

with three array members explicetly assigned to the array
on the initialization stage.

If that did happen it would be an implementation bug (as was the case in
the firefox/Mozilla versions discussed in the other thread).

And each and every *assigned* array member is
reflected as an enumerable object property of the
underlaying Object object. To see the difference (and the
real sense of undefined value) try this:

<script type="text/javascript">
function f(arg) {
for (var p in arg) {
window.alert(arg[p] || 'undefined');
}
window.alert('loops: ' + i);
}

function demo() {
var arr = ['A',,'B'];
arr[100] = 'C';
f(arr);
}

window.onload = demo;
</script>

arr[1] member gets an explicit assignment;

If it does then that would be in implementation bug.

thus then you treat your array as an Object type,

There is no meaningful sense in which anyone could treat an array as not
being an object type, as it always is of that type.

you see it as property "1" with value
undefined.
After arr[100] = 'C'; you're getting 96 members gap to
the next defined value. But arr[3]...arr[99] never participated
in any assignment operations. They are undefined and existing
only in the abstract array continuum space. Therefore they are
not reflected as object properties.

So, apart from demonstrating your ability to shamelessly post material
that is 100% factually false (that is; your assertions here about what
ECMA 262 3rd Ed. says and means are the opposite of reality) what is
your point?

At lest the other thread came to the (correct) conclusion that the
firefox/Mozilla behaviour described was an implementation bug.

Richard.


.



Relevant Pages

  • undefined vs. undefined (was: new Array() vs [])
    ... In case of an elision in an array initializer you *do* assign values to ... var arr = ... And each and every *assigned* array member is ... arrmember gets an explicit assignment; ...
    (comp.lang.javascript)
  • Re: array lines shifting
    ... What is it ment to do? ... This is your array: ... What is the goal, the goal is, to rotate array rows, the ... There is an assignment to stored value ...
    (alt.comp.lang.learn.c-cpp)
  • Re: array lines shifting
    ... What is it ment to do? ... This is your array: ... What is the goal, the goal is, to rotate array rows, the ... There is an assignment to stored value ...
    (alt.comp.lang.learn.c-cpp)
  • Re: GetCrossReferenceItems and sparse returns for wdCaptionTable
    ... The array that you get back from GetCrossReferenceItems is equivalent to the ... The Reference Type you must give it is equivalent to the ... wdCaptionFigure, wdCaptionEquation. ...
    (microsoft.public.word.vba.general)
  • Re: Automatic (?) array bounds checking
    ... the automatic array result and the array I was assigning it to. ... and then the assignment statement ... function allocates a temporary result. ... Some compilers ought to be able to detect such things as shape mismatch ...
    (comp.lang.fortran)