473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Array - What am I doing wrong?

<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT>
<!--

var factor_val = new Array(8,7)

factor_val[1,1] = 68.8
factor_val[1,2] = 55
factor_val[1,3] = 45.5
factor_val[1,4] = 42.3
factor_val[1,5] = 39.3
factor_val[1,6] = 34.4
factor_val[1,7] = 30.6
factor_val[2,1] = 36.7
factor_val[2,2] = 31
factor_val[2,3] = 25.8
factor_val[2,4] = 23.8
factor_val[2,5] = 22.1
factor_val[2,6] = 19.4
factor_val[2,7] = 17.2
factor_val[3,1] = 30.6
factor_val[3,2] = 26.5
factor_val[3,3] = 20.4
factor_val[3,4] = 18.8
factor_val[3,5] = 17.5
factor_val[3,6] = 15.3
factor_val[3,7] = 13.6
factor_val[4,1] = 24.3
factor_val[4,2] = 19.7
factor_val[4,3] = 16.5
factor_val[4,4] = 15.2
factor_val[4,5] = 14.1
factor_val[4,6] = 12.4
factor_val[4,7] = 11
factor_val[5,1] = 17.2
factor_val[5,2] = 13.7
factor_val[5,3] = 11.5
factor_val[5,4] = 10.6
factor_val[5,5] = 9.8
factor_val[5,6] = 8.6
factor_val[5,7] = 7.6
factor_val[6,1] = 9.7
factor_val[6,2] = 7.7
factor_val[6,3] = 6.5
factor_val[6,4] = 5.9
factor_val[6,5] = 5.5
factor_val[6,6] = 4.8
factor_val[6,7] = 4.3
factor_val[7,1] = 7.6
factor_val[7,2] = 6
factor_val[7,3] = 5.1
factor_val[7,4] = 4.7
factor_val[7,5] = 4.4
factor_val[7,6] = 3.8
factor_val[7,7] = 3.4
factor_val[8,1] = 4
factor_val[8,2] = 3
factor_val[8,3] = 2.7
factor_val[8,4] = 2.6
factor_val[8,5] = 2.5
factor_val[8,6] = 2
factor_val[8,7] = 1.7

function compute(form)
{
var myindex_x = form.diameter.selectedIndex;
var myindex_y = form.depth.selectedIndex;

if (myindex_x == 0)
{
alert("Select a Diameter.");
}
else if (myindex_y == 0)
{
alert("Select a Depth.");
}
else
{
form.x_val.value = myindex_x;
form.y_val.value = myindex_y;
form.f_val.value = factor_val[myindex_x, myindex_y];
form.answer_val.value = form.num_of_holes.value/factor_val[myindex_x,
myindex_y];

}
}

-->
</SCRIPT>
</HEAD>

<BODY>

<form>

<p><input type="text" name="num_of_holes" size="4" value="0"> Number of
Holes</p>

<p>
<select name="diameter">
<option>Select the Diameter</option>
<option>6</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>12</option>
<option>16</option>
<option>18</option>
<option>24</option>
</select>
</p>

<p>
<select name="depth">
<option>Select the Depth</option>
<option>24</option>
<option>30</option>
<option>36</option>
<option>39</option>
<option>42</option>
<option>48</option>
<option>54</option>
</select>
</p>

<p><font color="#0000FF"><input type="text" name="x_val" size="4" value="0"
onFocus='this.blur()'> X</font></p>
<p><font color="#0000FF"><input type="text" name="y_val" size="4" value="0"
onFocus='this.blur()'> Y</font></p>
<p><font color="#0000FF"><input type="text" name="f_val" size="4" value="0"
onFocus='this.blur()'> Factor</font></p>
<p><input type="text" name="answer_val" size="6" value="0"
onFocus='this.blur()'> Answer</p>

</p>
<INPUT TYPE="BUTTON" VALUE="Calculate" onClick="compute(this.form)"><input
type="reset" value="Reset" name="B2">
</form>
</BODY>
</HTML>
Jul 20 '05 #1
15 2414
M.Siler wrote on 16 nov 2003 in comp.lang.javascript:
var factor_val = new Array(8,7)


There are no cats in America,
I mean there are no multidimensional arrays in Javascript.
<script>

var factor_val = new Array(8,7)

alert(factor_val[0]) // shows 8
alert(factor_val[1]) // shows 7

</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #2
"Evertjan." wrote:

M.Siler wrote on 16 nov 2003 in comp.lang.javascript:
var factor_val = new Array(8,7)


There are no cats in America,
I mean there are no multidimensional arrays in Javascript.

<script>

var factor_val = new Array(8,7)

alert(factor_val[0]) // shows 8
alert(factor_val[1]) // shows 7

</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

I don't agree and the NS javascript specs agree with me: there are
multidimensional arrays in Javascript, except you have to define them
slightly differently from what has been done in the sample code.

The following comes straight from the Client-Side Javascript Reference
(v 1.3):

** START QUOTE **

Example 2: Two-dimensional array. The following code creates a
two-dimensional array and assigns the results to myVar.

myVar="Multidimensional array test; "
a = new Array(4)
for (i=0; i < 4; i++) {
a[i] = new Array(4)
for (j=0; j < 4; j++) {
a[i][j] = "["+i+","+j+"]"
}
}
for (i=0; i < 4; i++) {
str = "Row "+i+":"
for (j=0; j < 4; j++) {
str += a[i][j]
}
myVar += str +"; "
}

This example assigns the following string to myVar (line breaks are used
here for readability):

Multidimensional array test;
Row 0:[0,0][0,1][0,2][0,3];
Row 1:[1,0][1,1][1,2][1,3];
Row 2:[2,0][2,1][2,2][2,3];
Row 3:[3,0][3,1][3,2][3,3];

** END OF QUOTE **
So to answer Mr Siler's question:
You have to define your array using the following method:
** Please take note: normal array assignments start at 0 (not at 1), so
the first argument should be refered to as factor_val[0][0] NOT
factor_val[1][1] and definitely NOT factor_val[1,0].

var factor_val = new Array();
factor_val[0] = new Array();
factor_val[0][0] = 68.8;
factor_val[0][1] = 55;
factor_val[0][2] = 45.5;
factor_val[0][3] = 42.3;
etc...
factor_val[1] = new Array();
factor_val[1][0] = 36.7;
factor_val[1][1] = 31;
etc...
etc...

I presume you get my drift.

Good luck,
Juliette
Jul 20 '05 #3
Juliette <"jrf[spamblock]"@jokeaday.net> writes:
"Evertjan." wrote:

M.Siler wrote on 16 nov 2003 in comp.lang.javascript:
> var factor_val = new Array(8,7)
>
There are no cats in America,
I mean there are no multidimensional arrays in Javascript.

<script>

var factor_val = new Array(8,7)

alert(factor_val[0]) // shows 8
alert(factor_val[1]) // shows 7

</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

I don't agree and the NS javascript specs agree with me: there are
multidimensional arrays in Javascript, except you have to define them
slightly differently from what has been done in the sample code.


I disagree with you. There are no multidimensional arrays in
Javascript. There is no single array that is multidimensional. What
you do have is arrays containing arrays, which is a completely
different thing (although it can be used to emulate multidimensional
arrays in their absence).

C has multidimensional arrays. Java doesn't, it only has arrays of
arrays.

This is ofcourse splitting hairs, i.e., purely a matter of
terminology ...
The following comes straight from the Client-Side Javascript Reference
(v 1.3):

** START QUOTE **

Example 2: Two-dimensional array. The following code creates a
two-dimensional array and assigns the results to myVar.
.... and I disagree with their use of terminology.

So to answer Mr Siler's question:
You have to define your array using the following method:
.... a perfectly good advice.
var factor_val = new Array();
factor_val[0] = new Array();
factor_val[0][0] = 68.8;
factor_val[0][1] = 55;
factor_val[0][2] = 45.5;
factor_val[0][3] = 42.3;
etc...
factor_val[1] = new Array();
factor_val[1][0] = 36.7;
factor_val[1][1] = 31;
etc...


You can also use array literals:
var factor_val = [[68.8, 55, 45.5, 42.3, 39.3, 34.4, 30.6],
[36.7, 31, ... ],
...
[..., 2.6, 2.5, 2, 1.7]
];

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4
I have been able to set up arrays as follows:

MyArray = [[1,2,3],[4,5,6],[7,8,9]]

MyArray[1][1]=5
etc.

In article <3F***************@jokeaday.net>, Juliette
<"jrf[spamblock]"@jokeaday.net> wrote:
"Evertjan." wrote:

M.Siler wrote on 16 nov 2003 in comp.lang.javascript:
var factor_val = new Array(8,7)


There are no cats in America,
I mean there are no multidimensional arrays in Javascript.

<script>

var factor_val = new Array(8,7)

alert(factor_val[0]) // shows 8
alert(factor_val[1]) // shows 7

</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

I don't agree and the NS javascript specs agree with me: there are
multidimensional arrays in Javascript, except you have to define them
slightly differently from what has been done in the sample code.

The following comes straight from the Client-Side Javascript Reference
(v 1.3):

** START QUOTE **

Example 2: Two-dimensional array. The following code creates a
two-dimensional array and assigns the results to myVar.

myVar="Multidimensional array test; "
a = new Array(4)
for (i=0; i < 4; i++) {
a[i] = new Array(4)
for (j=0; j < 4; j++) {
a[i][j] = "["+i+","+j+"]"
}
}
for (i=0; i < 4; i++) {
str = "Row "+i+":"
for (j=0; j < 4; j++) {
str += a[i][j]
}
myVar += str +"; "
}

This example assigns the following string to myVar (line breaks are used
here for readability):

Multidimensional array test;
Row 0:[0,0][0,1][0,2][0,3];
Row 1:[1,0][1,1][1,2][1,3];
Row 2:[2,0][2,1][2,2][2,3];
Row 3:[3,0][3,1][3,2][3,3];

** END OF QUOTE **
So to answer Mr Siler's question:
You have to define your array using the following method:
** Please take note: normal array assignments start at 0 (not at 1), so
the first argument should be refered to as factor_val[0][0] NOT
factor_val[1][1] and definitely NOT factor_val[1,0].

var factor_val = new Array();
factor_val[0] = new Array();
factor_val[0][0] = 68.8;
factor_val[0][1] = 55;
factor_val[0][2] = 45.5;
factor_val[0][3] = 42.3;
etc...
factor_val[1] = new Array();
factor_val[1][0] = 36.7;
factor_val[1][1] = 31;
etc...
etc...

I presume you get my drift.

Good luck,
Juliette

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 20 '05 #5
Lasse Reichstein Nielsen wrote:

Juliette <"jrf[spamblock]"@jokeaday.net> writes:
"Evertjan." wrote:

M.Siler wrote on 16 nov 2003 in comp.lang.javascript:

> var factor_val = new Array(8,7)
>

There are no cats in America,
I mean there are no multidimensional arrays in Javascript.

<script>

var factor_val = new Array(8,7)

alert(factor_val[0]) // shows 8
alert(factor_val[1]) // shows 7

</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

I don't agree and the NS javascript specs agree with me: there are
multidimensional arrays in Javascript, except you have to define them
slightly differently from what has been done in the sample code.


I disagree with you. There are no multidimensional arrays in
Javascript. There is no single array that is multidimensional. What
you do have is arrays containing arrays, which is a completely
different thing (although it can be used to emulate multidimensional
arrays in their absence).

C has multidimensional arrays. Java doesn't, it only has arrays of
arrays.

This is ofcourse splitting hairs, i.e., purely a matter of
terminology ...
The following comes straight from the Client-Side Javascript Reference
(v 1.3):

** START QUOTE **

Example 2: Two-dimensional array. The following code creates a
two-dimensional array and assigns the results to myVar.


... and I disagree with their use of terminology.
So to answer Mr Siler's question:
You have to define your array using the following method:


... a perfectly good advice.
var factor_val = new Array();
factor_val[0] = new Array();
factor_val[0][0] = 68.8;
factor_val[0][1] = 55;
factor_val[0][2] = 45.5;
factor_val[0][3] = 42.3;
etc...
factor_val[1] = new Array();
factor_val[1][0] = 36.7;
factor_val[1][1] = 31;
etc...


You can also use array literals:
var factor_val = [[68.8, 55, 45.5, 42.3, 39.3, 34.4, 30.6],
[36.7, 31, ... ],
...
[..., 2.6, 2.5, 2, 1.7]
];

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'

Lasse,

Of course you are completely correct concerning the terminology, but at
the end of the day the effect is what counts and as desired.

The shorthand array definition which you show is absolutely correct and
much more efficient.
The longhand version just goes to show what is actually being done ;-).

Greetz, Juliette
Jul 20 '05 #6
Thanks for everyone help... I agree it's not a true multidimensional array,
but it works close enough like one... here's what I ended up with.

-----------------
<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT>
<!--

var row_1 = new Array(68.8, 36.7, 30.6, 24.3, 17.2, 9.7, 7.6, 4)
var row_2 = new Array(55, 31, 26.5, 19.7, 13.7, 7.7, 6, 3)
var row_3 = new Array(45.5, 25.8, 20.4, 16.5, 11.5, 6.5, 5.1, 2.7)
var row_4 = new Array(42.3, 23.8, 18.8, 15.2, 10.6, 5.9, 4.7, 2.6)
var row_5 = new Array(39.3, 22.1, 17.5, 14.1, 9.8, 5.5, 4.4, 2.5)
var row_6 = new Array(34.4, 19.4, 15.3, 12.4, 8.6, 4.8, 3.8, 2)
var row_7 = new Array(30.6, 17.2, 13.6, 11, 7.6, 4.3, 3.4, 1.7)

var M = new Array(row_1, row_2, row_3, row_4, row_5, row_6, row_7)

function compute(form)
{
var myindex_x = form.diameter.selectedIndex;
var myindex_y = form.depth.selectedIndex;

if (myindex_x == 0)
{
alert("Select a Diameter.");
}
else if (myindex_y == 0)
{
alert("Select a Depth.");
}
else
{
form.f_val.value = M[myindex_y-1][myindex_x-1];
form.answer_val.value =
form.num_of_holes.value/M[myindex_y-1][myindex_x-1];
}
}

-->
</SCRIPT>
</HEAD>

<BODY>

<form>

<p><input type="text" name="num_of_holes" size="4" value="0"> Number of
Holes</p>

<p>
<select name="diameter">
<option>Select the</option>
<option>6</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>12</option>
<option>16</option>
<option>18</option>
<option>24</option>
</select> Diameter</p>

<p>
<select name="depth">
<option>Select the</option>
<option>24</option>
<option>30</option>
<option>36</option>
<option>39</option>
<option>42</option>
<option>48</option>
<option>54</option>
</select> Depth</p>

<p><font color="#0000FF"><input type="text" name="f_val" size="4" value="0"
onFocus='this.blur()'> Factor</font></p>
<p><input type="text" name="answer_val" size="6" value="0"
onFocus='this.blur()'> Answer</p>

</p>
<INPUT TYPE="BUTTON" VALUE="Calculate" onClick="compute(this.form)"><input
type="reset" value="Reset" name="B2">
</form>
</BODY>
</HTML>

-----------------

Thanks again!
"Juliette" <"jrf[spamblock]"@jokeaday.net> wrote in message
news:3F***************@jokeaday.net...
Lasse Reichstein Nielsen wrote:

Juliette <"jrf[spamblock]"@jokeaday.net> writes:
"Evertjan." wrote:
>
> M.Siler wrote on 16 nov 2003 in comp.lang.javascript:
>
> > var factor_val = new Array(8,7)
> >
>
> There are no cats in America,
> I mean there are no multidimensional arrays in Javascript.
>
> <script>
>
> var factor_val = new Array(8,7)
>
> alert(factor_val[0]) // shows 8
> alert(factor_val[1]) // shows 7
>
> </script>
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)
I don't agree and the NS javascript specs agree with me: there are
multidimensional arrays in Javascript, except you have to define them
slightly differently from what has been done in the sample code.


I disagree with you. There are no multidimensional arrays in
Javascript. There is no single array that is multidimensional. What
you do have is arrays containing arrays, which is a completely
different thing (although it can be used to emulate multidimensional
arrays in their absence).

C has multidimensional arrays. Java doesn't, it only has arrays of
arrays.

This is ofcourse splitting hairs, i.e., purely a matter of
terminology ...
The following comes straight from the Client-Side Javascript Reference
(v 1.3):

** START QUOTE **

Example 2: Two-dimensional array. The following code creates a
two-dimensional array and assigns the results to myVar.


... and I disagree with their use of terminology.
So to answer Mr Siler's question:
You have to define your array using the following method:


... a perfectly good advice.
var factor_val = new Array();
factor_val[0] = new Array();
factor_val[0][0] = 68.8;
factor_val[0][1] = 55;
factor_val[0][2] = 45.5;
factor_val[0][3] = 42.3;
etc...
factor_val[1] = new Array();
factor_val[1][0] = 36.7;
factor_val[1][1] = 31;
etc...


You can also use array literals:
var factor_val = [[68.8, 55, 45.5, 42.3, 39.3, 34.4, 30.6],
[36.7, 31, ... ],
...
[..., 2.6, 2.5, 2, 1.7]
];

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html> 'Faith without judgement merely degrades the spirit divine.'

Lasse,

Of course you are completely correct concerning the terminology, but at
the end of the day the effect is what counts and as desired.

The shorthand array definition which you show is absolutely correct and
much more efficient.
The longhand version just goes to show what is actually being done ;-).

Greetz, Juliette

Jul 20 '05 #7
M.Siler wrote:
<HTML>
The DOCTYPE declaration is missing for valid HTML.
<HEAD>
The character set declaration with the `meta' element is missing for valid HTML.
<TITLE></TITLE>
I do hope this is only a test case since `title' is "the most important
element of an HTML document." (according to the W3C Style Guide.)
<SCRIPT>
The type attribute is missing for valid HTML 4:

<script type="text/javascript">
[...]
var row_1 = new Array(68.8, 36.7, 30.6, 24.3, 17.2, 9.7, 7.6, 4)
var row_2 = new Array(55, 31, 26.5, 19.7, 13.7, 7.7, 6, 3)
var row_3 = new Array(45.5, 25.8, 20.4, 16.5, 11.5, 6.5, 5.1, 2.7)
var row_4 = new Array(42.3, 23.8, 18.8, 15.2, 10.6, 5.9, 4.7, 2.6)
var row_5 = new Array(39.3, 22.1, 17.5, 14.1, 9.8, 5.5, 4.4, 2.5)
var row_6 = new Array(34.4, 19.4, 15.3, 12.4, 8.6, 4.8, 3.8, 2)
var row_7 = new Array(30.6, 17.2, 13.6, 11, 7.6, 4.3, 3.4, 1.7)

var M = new Array(row_1, row_2, row_3, row_4, row_5, row_6, row_7)


You are wasting memory and polluting the namespace by defining too many
(global) variables. Except of the identifier for the last variable, which
I recommend to start lower-cased and be more descriptive, the following is
equal to the above:

var matrix = new Array(
new Array(68.8, 36.7, 30.6, 24.3, 17.2, 9.7, 7.6, 4),
new Array(55, 31, 26.5, 19.7, 13.7, 7.7, 6, 3),
new Array(45.5, 25.8, 20.4, 16.5, 11.5, 6.5, 5.1, 2.7),
new Array(42.3, 23.8, 18.8, 15.2, 10.6, 5.9, 4.7, 2.6),
new Array(39.3, 22.1, 17.5, 14.1, 9.8, 5.5, 4.4, 2.5),
new Array(34.4, 19.4, 15.3, 12.4, 8.6, 4.8, 3.8, 2),
new Array(30.6, 17.2, 13.6, 11, 7.6, 4.3, 3.4, 1.7));

Or using Array literals:

var matrix = [
[68.8, 36.7, 30.6, 24.3, 17.2, 9.7, 7.6, 4],
[55, 31, 26.5, 19.7, 13.7, 7.7, 6, 3],
[45.5, 25.8, 20.4, 16.5, 11.5, 6.5, 5.1, 2.7],
[42.3, 23.8, 18.8, 15.2, 10.6, 5.9, 4.7, 2.6],
[39.3, 22.1, 17.5, 14.1, 9.8, 5.5, 4.4, 2.5],
[34.4, 19.4, 15.3, 12.4, 8.6, 4.8, 3.8, 2],
[30.6, 17.2, 13.6, 11, 7.6, 4.3, 3.4, 1.7]];

AFAIS the latter (Array literals having Array literals als
list elements) is not specified in ECMAScript Ed. 3 (CMIIW).
PointedEars
Jul 20 '05 #8
Thomas 'PointedEars' Lahn <Po*********@web.de> writes:
M.Siler wrote:
<HTML>
The DOCTYPE declaration is missing for valid HTML.


HTML 4, that is.
<HEAD>


The character set declaration with the `meta' element is missing for valid HTML.


The <meta http-equiv="Content-Type" ... > element is not required by
the HTML specification. The content-type can (should?) be supplied by
the server, that is what "http-equiv" means.
var matrix = [
[68.8, 36.7, 30.6, 24.3, 17.2, 9.7, 7.6, 4],
[55, 31, 26.5, 19.7, 13.7, 7.7, 6, 3],
[45.5, 25.8, 20.4, 16.5, 11.5, 6.5, 5.1, 2.7],
[42.3, 23.8, 18.8, 15.2, 10.6, 5.9, 4.7, 2.6],
[39.3, 22.1, 17.5, 14.1, 9.8, 5.5, 4.4, 2.5],
[34.4, 19.4, 15.3, 12.4, 8.6, 4.8, 3.8, 2],
[30.6, 17.2, 13.6, 11, 7.6, 4.3, 3.4, 1.7]];

AFAIS the latter (Array literals having Array literals als
list elements) is not specified in ECMAScript Ed. 3 (CMIIW).


YAW. (Shouldn't that be "CMIIAW", or are you abbreviating a
contraction?)

The relevant grammar productions are:

ArrayLiteral : [ ElementList ]
ElementList : ElementList , Elison_opt AssignmentExpression
AssignmentExpression : ConditionalExpression
ConditionalExpression : LogicalORExpression
LogicalORExpression : LogicalANDExpression
LogicalANDExpression : BitwiseORExpression
BitwiseORExpression : BitwiseXORExpression
BitwiseXORExpression : BitwiseANDExpression
BitwiseANDExpression : EqualityExpression
EqualityExpression : RelationalExpression
RelationalExpression : ShiftExpression
ShiftExpression : AdditiveExpression
AdditiveExpression : MultiplicativeExpression
MultiplicativeExpression : UnaryExpression
UnaryExpression : PostfixExpression
PostfixExpression : LeftHandSideExpression
LeftHandSideExpression : NewExpression
NewExpression : MemberExpression
MemberExpression : PrimaryExpression
PrimaryExpression : ArrayLiteral

Enjoy :)
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #9
In article <d6**********@hotpop.com>, Lasse Reichstein Nielsen <lr*@hotpop.com>
writes:
YAW. (Shouldn't that be "CMIIAW", or are you abbreviating a
contraction?)


WTFDYJS?

What the F*** did you just say? There are things to be said for abbreviations
when they may not be known to potential readers (I got the YAW, not the other
two)
--
Randy
Jul 20 '05 #10
hi************@aol.com (HikksNotAtHome) writes:
In article <d6**********@hotpop.com>, Lasse Reichstein Nielsen <lr*@hotpop.com>
writes:
YAW. (Shouldn't that be "CMIIAW", or are you abbreviating a
contraction?)


WTFDYJS?

What the F*** did you just say? There are things to be said for abbreviations
when they may not be known to potential readers (I got the YAW, not the other
two)


Ah, the person I responded to finished with "CMIIW", which I decoded as
"correct me if I'm wrong". The answer was ofcourse "YAW" (You are wrong).

If forced to do it, I would abbreviate "correct me if I'm wrong" as
CMIIAW, because I don't like to abbreviate a contraction.

Otherwise, I fully agree and normally try to avoid abbreviations, since
I don't understand all of them either (as a non-native English speaker)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #11
Lasse Reichstein Nielsen wrote:
Thomas 'PointedEars' Lahn <Po*********@web.de> writes:
M.Siler wrote:
<HTML>
The DOCTYPE declaration is missing for valid HTML.


HTML 4, that is.


It is required for *any* (valid) HTML:

http://www.w3.org/TR/html4/struct/global.html#h-7.2
<HEAD>


The character set declaration with the `meta' element is missing for valid HTML.


The <meta http-equiv="Content-Type" ... > element is not required by
the HTML specification. The content-type can (should?) be supplied by
the server, that is what "http-equiv" means.


http://www.w3.org/TR/html4/charset.html#doc-char-set

Validate a local document and you see it is required. It is, because HTML
is not required to be served via HTTP. You are right, the (HTTP) server
should supply the Content-Type along with the character set but if it does
not, the character set of the document differs from the server default (and
the author has no appropriate means to change that for the document) or if
there is no server, a user agent is required to obey the above declaration.
(XHTML is a different thing, of course, the `meta' element comes too late
for the XML parser, it requires the charset declaration within the XML
declaration before the DOCTYPE declaration.)
AFAIS the latter (Array literals having Array literals als
list elements) is not specified in ECMAScript Ed. 3 (CMIIW).


YAW.


I like that one :-) and I stand corrected.
(Shouldn't that be "CMIIAW",
No.
or are you abbreviating a contraction?)
Yes, and that is Usenet jargon. You may refer to the Jargon File or similar
dictionaries.
The relevant grammar productions are:
[...]

Enjoy :)


Thank you very much for your research. Using the same productions for the
most part[1], I could finally prove that object literals may also be nested
in themselves according to the specification(, a fact that has been denied
by somebody else (and I had not the energy to prove him wrong in those
days)). :)
\V/ Live long and prosper

PointedEars
___________
[1] ObjectLiteral : { PropertyNameAndValueList }
PropertyNameAndValueList : AssignmentExpression
...
PrimaryExpression : ObjectLiteral
Jul 20 '05 #12
Thomas 'PointedEars' Lahn <Po*********@web.de> writes:

[<!DOCTYPE> declaration]
It is required for *any* (valid) HTML:
Correct, my mistake.
http://www.w3.org/TR/html4/charset.html#doc-char-set
---
To address server or configuration limitations, HTML documents may
include explicit information about the document's character encoding;
the META element can be used to provide user agents with this
information.
---
Validate a local document and you see it is required.
Not if I tell the validator which character set to use.
It's a good idea to include the character encoding in the document,
but it is not required.
Thank you very much for your research. Using the same productions for the
most part[1], I could finally prove that object literals may also be nested
in themselves according to the specification(, a fact that has been denied
by somebody else (and I had not the energy to prove him wrong in those
days)). :)
It would me very bad design otherwise, if literal compound values could
not be nested, but could be embedded later.
I hope you can prove me mistaken on this one: Function declarations
are only allowed at the top level of programs or function bodies.
That means that

if (true) {
function foo(){}
}

is syntactically incorrect ECMAScript (it can't be an
ExpressionStatement containing a FunctionExpression, since
ExpressionStatements cannot start with "function"), and it
can't be a FunctionDeclaration.

Browsers treat the above as a function declaration.
\V/ Live long and prosper


\V/ \V/ - I am not a nerd!
-L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #13
In article <ad**********@hotpop.com>, Lasse Reichstein Nielsen
<lr*@hotpop.com> writes
<snip>
I hope you can prove me mistaken on this one: Function declarations
are only allowed at the top level of programs or function bodies.
That means that

if (true) {
function foo(){}
}

is syntactically incorrect ECMAScript (it can't be an
ExpressionStatement containing a FunctionExpression, since
ExpressionStatements cannot start with "function"), and it
can't be a FunctionDeclaration.

Browsers treat the above as a function declaration.


Think sneaky! This ...

<SCRIPT type="text/javascript">

if (2 == 2)
{
document.write("True ");
var f = function () { document.write("Wow!"); };
}
else
document.write("False ");

f();

</SCRIPT>

.... is legal, and does what you were afraid of.

John
--
John Harris
Jul 20 '05 #14
> >I hope you can prove me mistaken on this one: Function declarations
are only allowed at the top level of programs or function bodies.
Whoa. Hold the phone. That is not true. Function statements can appear anywhere
that a statement can appear. And function expressions can appear pretty much
anywhere.
That means that

if (true) {
function foo(){}
}

is syntactically incorrect ECMAScript (it can't be an
ExpressionStatement containing a FunctionExpression, since
ExpressionStatements cannot start with "function"), and it
can't be a FunctionDeclaration.

It is syntactically correct. Not only that,

(function (){ })();

is correct, too.
Think sneaky! This ...


There is no need to be sneaky when there are correct alternatives.

http://www.crockford.com/#javascript
Jul 20 '05 #15
"Douglas Crockford" <no****@covad.net> writes:
>I hope you can prove me mistaken on this one: Function declarations
>are only allowed at the top level of programs or function bodies.

Whoa. Hold the phone. That is not true.


I hope so, but I can't convince myself by looking at the ECMAScript
specification (December 1999 version, freshly downloaded from ECMA's
homepage[1]). I can, however, convince myself of the opposite.
Function statements can appear anywhere that a statement can
appear.
FunctionDeclaration can only be produced by SourceElement.
SourceElement can only be produced by SourceElements.
SourceElements can only be produced by Program or FunctionBody.

The productions are:
---
FunctionBody : See clause 13
SourceElements

Program : See clause 14
SourceElements

SourceElements : See clause 14
SourceElement
SourceElements SourceElement
SourceElement : See clause 14
Statement
FunctionDeclaration
---

That means that a function declaration can only occur directly
inside a function body or a program.

Statments in general can also occur inside a block:
---
Block : See 12.1
{ StatementList_opt }
StatementList : See 12.1
Statement
StatementList Statement
---
FunctionDeclarations can not appear here, or most other
places where statements can.

FunctionExpression can appear almost anywhere another expression can,
except at the beginning of an ExpressionStatement (yes, you can wrap
it in parenthese, but if you *don't*, it is not correct - in the
example, I didn't).
And function expressions can appear pretty much anywhere.
Can you show me a derivation of
if (true) {
function foo(){alert();}
foo();
}
in the ECMAScript syntax?

I added to "foo()" to suggest that browsers treat it as a function
declaration. If it is a function expression, then the scope of "foo"
would only be the body of the function. It isn't in Opera 7, IE 6,
Mozilla FB 0.7 or Netscape 4 (the browsers I have tested).

In fact, Opera and IE also accept and run:
if (true) {
foo();
function foo(){alert();}
}
while Mozilla FB and Netscape 4 says that "foo is not defined."
It is syntactically correct.
Prove it. :)
Not only that,

(function (){ })();

is correct, too.


Absolutely, that is a function expression, and the parenthesis at the
beginning makes it a legal expressionStatement. It is a completely
different beast.

Instead of the function declaration:
function foo(){...}
you can write the variable statement:
var foo = function foo(){...};
The only difference is that the function declaration should be
processed before any statements in the same scope are executed,
so you can use a function that is declared later in the code.

/L
[1]<URL:http://www.ecma-international.org/publications/standards/Ecma-262.htm>
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: LRW | last post by:
I have a page that's doing a search of a database, create an array and displays it. And I have it displaying the array just fine, but when I try to sort it, I get the error: Warning: sort()...
12
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are...
8
by: Gerald | last post by:
I have a problem with an array of pointers. In a program I'm writing, I have to read a file, containing thousands of short lines. The content of another file will be compared against each line...
12
by: anonymous | last post by:
Hi folks, I am in a fix trying to copy data to an array which is member of a structure. What I am doing right now is: char array = {0,1,2,3,4,5,6,7}; memcpy(structure.array, array, 8); Is...
11
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to...
4
by: Terry | last post by:
I'm building some dll assemblies that have in them the implementation of an abstract class defined in a different assembly. I'm trying to create objects of the type defined in the dlls with...
3
by: inkexit | last post by:
I need help figuring out what is wrong with my code. I posted here a few weeks ago with some code about creating self similar melodies in music. The coding style I'm being taught is apparently a...
8
by: Sam | last post by:
I have a situation occuring in my code and I just can't see to figure out why I have an structure called employee that will put all of the employee id's into a char array set to 10 struct...
14
by: abhi147 | last post by:
Hi , I want to convert an array of bytes like : {79,104,-37,-66,24,123,30,-26,-99,-8,80,-38,19,14,-127,-3} into Unicode character with ISO-8859-1 standard. Can anyone help me .. how should...
11
by: abhiM | last post by:
I have a struct that has an array in it. I need to assign space to the array in a function and pass the corresponding struct by reference to another function so that it can store values into the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.