Connecting Tech Pros Worldwide Help | Site Map

With clause syntax errors but how do I fix it?

Phil Powell
Guest
 
Posts: n/a
#1: Jul 20 '05
<script>
<!--

function isValidAlert() {
for (var i = 0; i < document.alertForm.length; i++) {
with (document.alertForm.elements[i]) {
if (.name == "text" || .name == "password" || .name == "textarea") {
if (.value == "") {
alert("Please enter a " + .name);
focus();
return false;
}
} else if (.name == "select-one") {
if (.options[document.alertForm.elements[i].selectedIndex].value ==
"") {
alert("Please select a " + .name);
return false;
}
}
}
}
}

//-->
</script>

I don't know the answer to this problem, I am getting syntax errors, and
"with" does not search well on any Javascript tutorial. So this is my only
option for help; can someone tell me what I did wrong?

Thanx
Phil


Laurent Bugnion, GalaSoft
Guest
 
Posts: n/a
#2: Jul 20 '05

re: With clause syntax errors but how do I fix it?


Hi,

Phil Powell wrote:
[color=blue]
> <script>
> <!--
>
> function isValidAlert() {
> for (var i = 0; i < document.alertForm.length; i++) {
> with (document.alertForm.elements[i]) {
> if (.name == "text" || .name == "password" || .name == "textarea") {
> if (.value == "") {
> alert("Please enter a " + .name);
> focus();
> return false;
> }
> } else if (.name == "select-one") {
> if (.options[document.alertForm.elements[i].selectedIndex].value ==
> "") {
> alert("Please select a " + .name);
> return false;
> }
> }
> }
> }
> }
>
> //-->
> </script>
>
> I don't know the answer to this problem, I am getting syntax errors, and
> "with" does not search well on any Javascript tutorial. So this is my only
> option for help; can someone tell me what I did wrong?
>
> Thanx
> Phil[/color]

"with" works in VB, but as far as I know, it doesn't in JavaScript. It
also doesn't in most current languages. Anyway, it makes the code
unreadable, and all in all it is good practice to not use it.

If you want to simplify long or complicated structures, you can always
redeclare them:

var myText = windowNumberOne.document.theNameOfTheForm.theNameO fTheText;

myText.value = "Hello world";

Laurent
--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

Laurent Bugnion, GalaSoft
Guest
 
Posts: n/a
#3: Jul 20 '05

re: With clause syntax errors but how do I fix it?


Correction, I was wrong. See below.

Laurent Bugnion, GalaSoft wrote:
[color=blue]
> Hi,
>
> Phil Powell wrote:
>[color=green]
>> <script>
>> <!--
>>
>> function isValidAlert() {
>> for (var i = 0; i < document.alertForm.length; i++) {
>> with (document.alertForm.elements[i]) {
>> if (.name == "text" || .name == "password" || .name == "textarea") {
>> if (.value == "") {
>> alert("Please enter a " + .name);
>> focus();
>> return false;
>> }
>> } else if (.name == "select-one") {
>> if (.options[document.alertForm.elements[i].selectedIndex].value ==
>> "") {
>> alert("Please select a " + .name);
>> return false;
>> }
>> }
>> }
>> }
>> }
>>
>> //-->
>> </script>
>>
>> I don't know the answer to this problem, I am getting syntax errors, and
>> "with" does not search well on any Javascript tutorial. So this is my
>> only
>> option for help; can someone tell me what I did wrong?
>>
>> Thanx
>> Phil[/color]
>
>
> "with" works in VB, but as far as I know, it doesn't in JavaScript. It
> also doesn't in most current languages. Anyway, it makes the code
> unreadable, and all in all it is good practice to not use it.
>
> If you want to simplify long or complicated structures, you can always
> redeclare them:
>
> var myText = windowNumberOne.document.theNameOfTheForm.theNameO fTheText;
>
> myText.value = "Hello world";
>
> Laurent[/color]

OK, I was wrong. With exists in JavaScript, as described in this example:

It is often convenient to use the with statement when a section of code
uses several math constants and methods, so you don't have to type
"Math" repeatedly. For example,

with (Math) {
a = PI * r*r
y = r*sin(theta)
x = r*cos(theta)
}

So the syntax is different (you don't use the '.' like in VB).

I stand, however, by the fact that it's bad practice to use it, and I
really recommend that you don't.

HTH,

Laurent
--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

Phil Powell
Guest
 
Posts: n/a
#4: Jul 20 '05

re: With clause syntax errors but how do I fix it?


Wow, damned one way or another.. that is awful!

I don't know what is more unreadable, how you view a "with" clause, or this:

document.alertForm.elements[i].options[document.alertForm.elements[i].select
edIndex].value

I think that is utterly unreadable myself! I was trying to come up with an
elegant and readable solution to parse through form elements for client-side
validation. :(

I remember you use "." in VB. Sorry but it's now

VB 1
Javascript 0

That is very unsafe to not use "." because of potential data collision.

Phil

"Laurent Bugnion, GalaSoft" <galasoft-LB@bluewin_NO_SPAM.ch> wrote in
message news:3f53877a_1@news.bluewin.ch...[color=blue]
> Correction, I was wrong. See below.
>
> Laurent Bugnion, GalaSoft wrote:
>[color=green]
> > Hi,
> >
> > Phil Powell wrote:
> >[color=darkred]
> >> <script>
> >> <!--
> >>
> >> function isValidAlert() {
> >> for (var i = 0; i < document.alertForm.length; i++) {
> >> with (document.alertForm.elements[i]) {
> >> if (.name == "text" || .name == "password" || .name == "textarea")[/color][/color][/color]
{[color=blue][color=green][color=darkred]
> >> if (.value == "") {
> >> alert("Please enter a " + .name);
> >> focus();
> >> return false;
> >> }
> >> } else if (.name == "select-one") {
> >> if (.options[document.alertForm.elements[i].selectedIndex].value[/color][/color][/color]
==[color=blue][color=green][color=darkred]
> >> "") {
> >> alert("Please select a " + .name);
> >> return false;
> >> }
> >> }
> >> }
> >> }
> >> }
> >>
> >> //-->
> >> </script>
> >>
> >> I don't know the answer to this problem, I am getting syntax errors,[/color][/color][/color]
and[color=blue][color=green][color=darkred]
> >> "with" does not search well on any Javascript tutorial. So this is my
> >> only
> >> option for help; can someone tell me what I did wrong?
> >>
> >> Thanx
> >> Phil[/color]
> >
> >
> > "with" works in VB, but as far as I know, it doesn't in JavaScript. It
> > also doesn't in most current languages. Anyway, it makes the code
> > unreadable, and all in all it is good practice to not use it.
> >
> > If you want to simplify long or complicated structures, you can always
> > redeclare them:
> >
> > var myText = windowNumberOne.document.theNameOfTheForm.theNameO fTheText;
> >
> > myText.value = "Hello world";
> >
> > Laurent[/color]
>
> OK, I was wrong. With exists in JavaScript, as described in this example:
>
> It is often convenient to use the with statement when a section of code
> uses several math constants and methods, so you don't have to type
> "Math" repeatedly. For example,
>
> with (Math) {
> a = PI * r*r
> y = r*sin(theta)
> x = r*cos(theta)
> }
>
> So the syntax is different (you don't use the '.' like in VB).
>
> I stand, however, by the fact that it's bad practice to use it, and I
> really recommend that you don't.
>
> HTH,
>
> Laurent
> --
> Laurent Bugnion, GalaSoft
> Webdesign, Java, javascript: http://www.galasoft-LB.ch
> Private/Malaysia: http://mypage.bluewin.ch/lbugnion
> Support children in Calcutta: http://www.calcutta-espoir.ch
>[/color]


DU
Guest
 
Posts: n/a
#5: Jul 20 '05

re: With clause syntax errors but how do I fix it?


Phil Powell wrote:
[color=blue]
> <script>
> <!--
>
> function isValidAlert() {
> for (var i = 0; i < document.alertForm.length; i++) {
> with (document.alertForm.elements[i])[/color]
{[color=blue]
> if (.name == "text" || .name == "password" || .name == "textarea") {[/color]

This seems suspicious. I bet it would be rather:

if (type == "text" || type == "password" || type == "textarea") {
[color=blue]
> if (.value == "")[/color]

if(value == "")

{[color=blue]
> alert("Please enter a " + .name);
> focus();
> return false;
> }
> } else if (.name == "select-one") {
> if (.options[document.alertForm.elements[i].selectedIndex].value ==
> "") {
> alert("Please select a " + .name);
> return false;[/color]

Remove "." everywhere and try to make your code more compact.
[color=blue]
> }
> }
> }
> }
> }
>
> //-->
> </script>
>
> I don't know the answer to this problem, I am getting syntax errors, and
> "with" does not search well on any Javascript tutorial. So this is my only
> option for help; can someone tell me what I did wrong?
>
> Thanx
> Phil
>
>[/color]

It is widely known that with statements are very cpu-demanding, RAM
demanding also and are best to be avoided. Even MSDN recommends this.

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunc...e7Section.html

DU
Guest
 
Posts: n/a
#6: Jul 20 '05

re: With clause syntax errors but how do I fix it?


Phil Powell wrote:
[color=blue]
> Wow, damned one way or another.. that is awful!
>
> I don't know what is more unreadable, how you view a "with" clause, or this:
>
> document.alertForm.elements[i].options[document.alertForm.elements[i].select
> edIndex].value
>
> I think that is utterly unreadable myself![/color]

Then just use a local variable to store each element (at the start of
your for loop). E.g.:

var IteratedFormElement = document.alertForm.elements[i];
(...)

if(IteratedFormElement.options[IteratedFormElement.selectedIndex].value
== "")
(...)

I was trying to come up with an[color=blue]
> elegant and readable solution to parse through form elements for client-side
> validation. :(
>[/color]

[snipped]

Finally, please avoid top-posting in this newsgroup. Top-posting
destroys logical reading context and chronological order of posts in
threads.

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunc...e7Section.html

Phil Powell
Guest
 
Posts: n/a
#7: Jul 20 '05

re: With clause syntax errors but how do I fix it?


top-posting? HUH? English, please, or Svenska.

Phil

"DU" <drunclear@hotREMOVEmail.com> wrote in message
news:bj02q2$bi1$1@news.eusc.inter.net...[color=blue]
> Phil Powell wrote:
>[color=green]
> > Wow, damned one way or another.. that is awful!
> >
> > I don't know what is more unreadable, how you view a "with" clause, or[/color][/color]
this:[color=blue][color=green]
> >
> >[/color][/color]
document.alertForm.elements[i].options[document.alertForm.elements[i].select[color=blue][color=green]
> > edIndex].value
> >
> > I think that is utterly unreadable myself![/color]
>
> Then just use a local variable to store each element (at the start of
> your for loop). E.g.:
>
> var IteratedFormElement = document.alertForm.elements[i];
> (...)
>
> if(IteratedFormElement.options[IteratedFormElement.selectedIndex].value
> == "")
> (...)
>
> I was trying to come up with an[color=green]
> > elegant and readable solution to parse through form elements for[/color][/color]
client-side[color=blue][color=green]
> > validation. :(
> >[/color]
>
> [snipped]
>
> Finally, please avoid top-posting in this newsgroup. Top-posting
> destroys logical reading context and chronological order of posts in
> threads.
>
> DU
> --
> Javascript and Browser bugs:
> http://www10.brinkster.com/doctorunclear/
> - Resources, help and tips for Netscape 7.x users and Composer
> - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
> http://www10.brinkster.com/doctorunc...e7Section.html
>[/color]


Janwillem Borleffs
Guest
 
Posts: n/a
#8: Jul 20 '05

re: With clause syntax errors but how do I fix it?


Top-posting is putting your reply on top of the message or phrase you are
replying to. As I'm doing now...

"Phil Powell" <soazine@erols.com> schreef in bericht
news:swM4b.92709$xf.26491@lakeread04...[color=blue]
> top-posting? HUH? English, please, or Svenska.
>[/color]

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

"Phil Powell" <soazine@erols.com> schreef in bericht
news:swM4b.92709$xf.26491@lakeread04...[color=blue]
> top-posting? HUH? English, please, or Svenska.
>[/color]

This is the proper way of replying to a message by putting your reply
beneath the message.


JW



Janwillem Borleffs
Guest
 
Posts: n/a
#9: Jul 20 '05

re: With clause syntax errors but how do I fix it?



"Phil Powell" <soazine@erols.com> schreef in bericht
news:AVL4b.92357$xf.24656@lakeread04...[color=blue]
> I remember you use "." in VB. Sorry but it's now
>
> VB 1
> Javascript 0
>
> That is very unsafe to not use "." because of potential data collision.
>[/color]

No, it's not, because the scope is limited to the with clause itself. Try
the following example:

<html>
<head>
<title> New Document </title>
<script type="text/javascript">
name = "Hello 1";

function doAlert() {
var name = "Hello 2";
with (document.forms[0].elements[0]) {
alert("Form element's name value: " + name);
}
alert("Global var name value: " + window['name']);
alert("Local var name value: " + name);
}
</script>
</head>

<body>
<form>
<input type="text" value="text" name="test">
<input type="button" onClick="doAlert()" value="Test">
</form>
</body>
</html>

BTW, I don't subscribe to Laurent's point of view regarding the with clause.


JW



Phil Powell
Guest
 
Posts: n/a
#10: Jul 20 '05

re: With clause syntax errors but how do I fix it?


Ok, assuming that you have the with clause with your example. See my
comments below.

Phil

"Janwillem Borleffs" <jwb@jwbfoto.demon.nl> wrote in message
news:3f53b7aa$0$28887$1b62eedf@news.euronet.nl...[color=blue]
>
> "Phil Powell" <soazine@erols.com> schreef in bericht
> news:AVL4b.92357$xf.24656@lakeread04...[color=green]
> > I remember you use "." in VB. Sorry but it's now
> >
> > VB 1
> > Javascript 0
> >
> > That is very unsafe to not use "." because of potential data collision.
> >[/color]
>
> No, it's not, because the scope is limited to the with clause itself. Try
> the following example:
>
> <html>
> <head>
> <title> New Document </title>
> <script type="text/javascript">
> name = "Hello 1";
>
> function doAlert() {
> var name = "Hello 2";
> with (document.forms[0].elements[0]) {
> alert("Form element's name value: " + name);
> }
> alert("Global var name value: " + window['name']);
> alert("Local var name value: " + name);
> }
> </script>[/color]

Ok, now, what if you need both the var "name" AND
document.forms[0].elements[0].name at the same time? You see, with
Javascript not permitting the VB solution you can't do both so easily. VB
you would have "name" and ".name".

Phil
[color=blue]
> </head>
>
> <body>
> <form>
> <input type="text" value="text" name="test">
> <input type="button" onClick="doAlert()" value="Test">
> </form>
> </body>
> </html>
>
> BTW, I don't subscribe to Laurent's point of view regarding the with[/color]
clause.[color=blue]
>
>
> JW
>
>
>[/color]


Phil Powell
Guest
 
Posts: n/a
#11: Jul 20 '05

re: With clause syntax errors but how do I fix it?


Maybe it's a comp.lang.javascript thing but I don't get it. What's wrong
with that? That is the conventional reply. I'd never think to look below
unless you direct me to look below for comments on a particular area; and I
only do that when I need to highlight something you have said.

I think DU's logic flow and mine are in different worlds.

Phil

"Janwillem Borleffs" <jwb@jwbfoto.demon.nl> wrote in message
news:3f53b19e$0$28907$1b62eedf@news.euronet.nl...[color=blue]
> Top-posting is putting your reply on top of the message or phrase you are
> replying to. As I'm doing now...
>
> "Phil Powell" <soazine@erols.com> schreef in bericht
> news:swM4b.92709$xf.26491@lakeread04...[color=green]
> > top-posting? HUH? English, please, or Svenska.
> >[/color]
>
> -----------------
>
> "Phil Powell" <soazine@erols.com> schreef in bericht
> news:swM4b.92709$xf.26491@lakeread04...[color=green]
> > top-posting? HUH? English, please, or Svenska.
> >[/color]
>
> This is the proper way of replying to a message by putting your reply
> beneath the message.
>
>
> JW
>
>
>[/color]


Janwillem Borleffs
Guest
 
Posts: n/a
#12: Jul 20 '05

re: With clause syntax errors but how do I fix it?



"Phil Powell" <soazine@erols.com> schreef in bericht
news:HMO4b.93315$xf.73424@lakeread04...[color=blue]
>
> Ok, now, what if you need both the var "name" AND
> document.forms[0].elements[0].name at the same time? You see, with
> Javascript not permitting the VB solution you can't do both so easily. VB
> you would have "name" and ".name".
>[/color]

Yes it does, but you must define the variable as a property of the function:

function doAlert() {
with (document.forms[0].elements[0]) {
alert("Form element's name value: " + name);
alert("Local var name value: " + doAlert.name);
}
}

doAlert.name = "Hello There";

I admit, with VB the syntax is more convenient. But as you can see, there
are ways of getting there with JavaScript too.

In a way, it even forces you to think about your program design. E.g., when
my script encounters a pre-defined property 'name', then I shouldn't define
a variable with the same name. This is a good thing in my point of view.


JW



Phil Powell
Guest
 
Posts: n/a
#13: Jul 20 '05

re: With clause syntax errors but how do I fix it?


Never mind, you lost me completely.

Phil

"DU" <drunclear@hotREMOVEmail.com> wrote in message
news:bj0f2t$g4g$1@news.eusc.inter.net...[color=blue]
>
> http://www10.brinkster.com/doctorunc...e7Section.html
> - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
> - Resources, help and tips for Netscape 7.x users and Composer
> http://www10.brinkster.com/doctorunclear/
> Javascript and Browser bugs:
> --
> DU
>
>
> top to bottom, not from bottom to top.
> preferences then? Because 99.99% of people in this newsgroup read from
> Are you saying that you read from bottom to top? What are your reading[color=green]
> >
> > Phil
> >
> > I think DU's logic flow and mine are in different worlds.
> >
> > only do that when I need to highlight something you have said.
> > unless you direct me to look below for comments on a particular area;[/color]
> and I[color=green]
> > with that? That is the conventional reply. I'd never think to look[/color][/color]
below[color=blue][color=green]
> > Maybe it's a comp.lang.javascript thing but I don't get it. What's[/color][/color]
wrong[color=blue]
> Phil Powell wrote:
>
> [snipped]
>
>
>
>
>
>
>
>[/color]


Phil Powell
Guest
 
Posts: n/a
#14: Jul 20 '05

re: With clause syntax errors but how do I fix it?


That is a Java/CF/PHP solution moreso than Javascript. It appears
Javascript is becoming more like Java every day!!!

I never knew you could do that!

Phil

"Janwillem Borleffs" <jwb@jwbfoto.demon.nl> wrote in message
news:3f53c17d$0$28893$1b62eedf@news.euronet.nl...[color=blue]
>
> "Phil Powell" <soazine@erols.com> schreef in bericht
> news:HMO4b.93315$xf.73424@lakeread04...[color=green]
> >
> > Ok, now, what if you need both the var "name" AND
> > document.forms[0].elements[0].name at the same time? You see, with
> > Javascript not permitting the VB solution you can't do both so easily.[/color][/color]
VB[color=blue][color=green]
> > you would have "name" and ".name".
> >[/color]
>
> Yes it does, but you must define the variable as a property of the[/color]
function:[color=blue]
>
> function doAlert() {
> with (document.forms[0].elements[0]) {
> alert("Form element's name value: " + name);
> alert("Local var name value: " + doAlert.name);
> }
> }
>
> doAlert.name = "Hello There";
>
> I admit, with VB the syntax is more convenient. But as you can see, there
> are ways of getting there with JavaScript too.
>
> In a way, it even forces you to think about your program design. E.g.,[/color]
when[color=blue]
> my script encounters a pre-defined property 'name', then I shouldn't[/color]
define[color=blue]
> a variable with the same name. This is a good thing in my point of view.
>
>
> JW
>
>
>[/color]


Jim Ley
Guest
 
Posts: n/a
#15: Jul 20 '05

re: With clause syntax errors but how do I fix it?


On Mon, 1 Sep 2003 18:12:13 -0400, "Phil Powell" <soazine@erols.com>
wrote:
[color=blue]
>That is a Java/CF/PHP solution moreso than Javascript. It appears
>Javascript is becoming more like Java every day!!![/color]

Javascript hasn't changed in a number of years....
[color=blue][color=green]
>> function doAlert() {
>> with (document.forms[0].elements[0]) {
>> alert("Form element's name value: " + name);
>> alert("Local var name value: " + doAlert.name);
>> }
>> }[/color][/color]

with is considerably slower to execute and best avoided entirely.

Please learn how to post, it's not "top or bottom", it's snipped
interleaved quoting, your lack of snipping is your biggest problem.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Dr John Stockton
Guest
 
Posts: n/a
#16: Jul 20 '05

re: With clause syntax errors but how do I fix it?


JRS: In article <bj02q2$bi1$1@news.eusc.inter.net>, seen in
news:comp.lang.javascript, DU <drunclear@hotREMOVEmail.com> posted at
Mon, 1 Sep 2003 14:23:00 :-[color=blue]
>
>Finally, please avoid top-posting in this newsgroup.[/color]

The term "top-posting" should not be used to a newcomer, since it will
not be understood by the average innocent top-poster.

Something like "responses should follow trimmed quotes" does not take
much longer to type.

Alternatively, if "top-posting" is used, the term should be defined in
the FAQ, and "; see FAQ" added. Plus, preferably, a link to the FAQ.



IMHO, javascript 'with' is a useful tool which can readily be misused.
IMHO, it can be good to use it when anyone reading the code for the
first time will, having not noticed the 'with', be able to deduce it.

with (document) {
write('This<br>')
write(That, [them])
}

with (MyDate)
document.write(getFullYear()+'/'+LZ(getMonth()+1)+
'/'+LZ(getDate()))

Where the contents of the with parentheses would be lengthy, the
alternative of using an auxiliary variable is that a new variable,
probably terse, will remain in scope until the end of the block; a human
author might reuse it without remembering to give it a new value.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Douglas Crockford
Guest
 
Posts: n/a
#17: Jul 20 '05

re: With clause syntax errors but how do I fix it?


> I don't know what is more unreadable, how you view a "with" clause, or this:[color=blue]
>
> document.alertForm.elements[i].options[document.alertForm.elements[i].select
> edIndex].value
>
> I think that is utterly unreadable myself! I was trying to come up with an
> elegant and readable solution to parse through form elements for client-side
> validation. :([/color]

The with statement should be avoided. Use a var to do what you would do with
with.

var e = document.alertForm.elements[i];
... e.options[e.selectedIndex].value ...

The var lets you be explicit, while the with can have surprising and seemingly
random behavior. The appearance of with in the language was well intentioned,
but it was a mistake and it should be removed.

http://www.crockford.com/javascript/survey.html

DU
Guest
 
Posts: n/a
#18: Jul 20 '05

re: With clause syntax errors but how do I fix it?


Dr John Stockton wrote:
[color=blue]
> JRS: In article <bj02q2$bi1$1@news.eusc.inter.net>, seen in
> news:comp.lang.javascript, DU <drunclear@hotREMOVEmail.com> posted at
> Mon, 1 Sep 2003 14:23:00 :-
>[color=green]
>>Finally, please avoid top-posting in this newsgroup.[/color]
>
>
> The term "top-posting" should not be used to a newcomer, since it will
> not be understood by the average innocent top-poster.
>[/color]

How do you figure out who is a newcomer in a newsgroup? How can you
reasonably do that?
[color=blue]
> Something like "responses should follow trimmed quotes" does not take
> much longer to type.
>
> Alternatively, if "top-posting" is used, the term should be defined in
> the FAQ, and "; see FAQ" added. Plus, preferably, a link to the FAQ.
>
>[/color]

I'm all for defining "top-posting" in this newsgroup FAQ and I'm all for
explaining why top-posting just makes reading posts, replies and threads
harder for others.
Top-posting is not the natural reading direction for 99.99% of users in
this newsgroup... unless you really read from bottom to top (like
ancient Chinese).
Top-posting destroys chronological order of posts in threads.
Top-posting destroys logical reading context.
Top-posting makes others constantly scroll up and down to figure out
what was said and then what was replied: there is no book, document,
paper anywhere which goes like that. No one reads a book from end to
start. No one reads an interview in a magazine by first reading the
answers to questions. No one reads solutions first and then problem
descriptions. I don't video-tape a movie from end to start.
Top-posting generally makes it harder to understand message posts context.

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunc...e7Section.html

Phil Powell
Guest
 
Posts: n/a
#19: Jul 20 '05

re: With clause syntax errors but how do I fix it?


Thanx for your help.

"DU" <drunclear@hotREMOVEmail.com> wrote in message
news:bj2jv8$aq1$1@news.eusc.inter.net...[color=blue]
> Dr John Stockton wrote:
>[color=green]
> > JRS: In article <bj02q2$bi1$1@news.eusc.inter.net>, seen in
> > news:comp.lang.javascript, DU <drunclear@hotREMOVEmail.com> posted at
> > Mon, 1 Sep 2003 14:23:00 :-
> >[color=darkred]
> >>Finally, please avoid top-posting in this newsgroup.[/color]
> >
> >
> > The term "top-posting" should not be used to a newcomer, since it will
> > not be understood by the average innocent top-poster.
> >[/color]
>
> How do you figure out who is a newcomer in a newsgroup? How can you
> reasonably do that?
>[color=green]
> > Something like "responses should follow trimmed quotes" does not take
> > much longer to type.
> >
> > Alternatively, if "top-posting" is used, the term should be defined in
> > the FAQ, and "; see FAQ" added. Plus, preferably, a link to the FAQ.
> >
> >[/color]
>
> I'm all for defining "top-posting" in this newsgroup FAQ and I'm all for
> explaining why top-posting just makes reading posts, replies and threads
> harder for others.
> Top-posting is not the natural reading direction for 99.99% of users in
> this newsgroup... unless you really read from bottom to top (like
> ancient Chinese).
> Top-posting destroys chronological order of posts in threads.
> Top-posting destroys logical reading context.
> Top-posting makes others constantly scroll up and down to figure out
> what was said and then what was replied: there is no book, document,
> paper anywhere which goes like that. No one reads a book from end to
> start. No one reads an interview in a magazine by first reading the
> answers to questions. No one reads solutions first and then problem
> descriptions. I don't video-tape a movie from end to start.
> Top-posting generally makes it harder to understand message posts context.
>
> DU
> --
> Javascript and Browser bugs:
> http://www10.brinkster.com/doctorunclear/
> - Resources, help and tips for Netscape 7.x users and Composer
> - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
> http://www10.brinkster.com/doctorunc...e7Section.html
>[/color]


Lasse Reichstein Nielsen
Guest
 
Posts: n/a
#20: Jul 20 '05

re: With clause syntax errors but how do I fix it?


"Douglas Crockford" <nospam@laserlink.net> writes:
[color=blue]
> The var lets you be explicit, while the with can have surprising and
> seemingly random behavior.[/color]

Can you give examples of deliberate use of "with" that has surpricing
and seemingly random behavior?
[color=blue]
> The appearance of with in the language
> was well intentioned, but it was a mistake and it should be removed.[/color]
[color=blue]
> http://www.crockford.com/javascript/survey.html[/color]

(where all you say is "The with statement should be avoided" :))
/L
--
Lasse Reichstein Nielsen - lrn@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Laurent Bugnion, GalaSoft
Guest
 
Posts: n/a
#21: Jul 20 '05

re: With clause syntax errors but how do I fix it?


Hi,

Lasse Reichstein Nielsen wrote:
[color=blue]
> "Douglas Crockford" <nospam@laserlink.net> writes:
>
>[color=green]
>>The var lets you be explicit, while the with can have surprising and
>>seemingly random behavior.[/color]
>
>
> Can you give examples of deliberate use of "with" that has surpricing
> and seemingly random behavior?
>
>[color=green]
>>The appearance of with in the language
>>was well intentioned, but it was a mistake and it should be removed.[/color]
>
>[color=green]
>>http://www.crockford.com/javascript/survey.html[/color]
>
>
> (where all you say is "The with statement should be avoided" :))
> /L[/color]

Here is a very simple example to illustrate the problem:

var name = "Laurent Bugnion";

with ( document.formName )
{
alert( name );
}

This very simple example is already confusing, because I am not supposed
to know that there is a property called "name" in the Form object. I
cannot know that a property named like this exists in the object without
reading the API documentation.

This very simple example is not very confusing, however, because it
deals with an object and a property that we all know well. However, I
can do that with any other object, for which an API documentation might
not be available, might be more or less readable, etc...

Besides, "with" statements can be replaced by local variables, who have
all the advantages and none of the inconvenients. The readability will
be much better (you can event comment in the code why you feel the need
to replace one construct by another one, etc...).

Not even mentioning the fact that others stated, that "with" is slow,
memory intensive, etc..., I find that it complicates the code without
being useful. Since it is always good to make the readibility of your
code better, I would really recommend dropping "with" statements and
using explicit local variable declaration (and duly commented too) instead.

Hope that helps,

Laurent
--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

Lasse Reichstein Nielsen
Guest
 
Posts: n/a
#22: Jul 20 '05

re: With clause syntax errors but how do I fix it?


"Laurent Bugnion, GalaSoft" <galasoft-LB@bluewin_NO_SPAM.ch> writes:
[color=blue]
> Here is a very simple example to illustrate the problem:
>
> var name = "Laurent Bugnion";
>
> with ( document.formName )
> {
> alert( name );
> }
>
> This very simple example is already confusing, because I am not
> supposed to know that there is a property called "name" in the Form
> object. I cannot know that a property named like this exists in the
> object without reading the API documentation.[/color]

The point is that you should not use the "with" statement without
knowing your object. I can see that that makes it a dangerous
construction for beginners. It also means that you should either
use "with" on objects you have created yourself, and when using
it on other objects, don't access other variables directly.
[color=blue]
> This very simple example is not very confusing, however, because it
> deals with an object and a property that we all know well. However, I
> can do that with any other object, for which an API documentation
> might not be available, might be more or less readable, etc...[/color]

Yes, know your object, or don't "with" it! :)
[color=blue]
> Besides, "with" statements can be replaced by local variables, who
> have all the advantages and none of the inconvenients. The readability
> will be much better (you can event comment in the code why you feel
> the need to replace one construct by another one, etc...).[/color]

That is a point. There is not much saved between writing
objProperty
and
o.objProperty
[color=blue]
> Not even mentioning the fact that others stated, that "with" is slow,
> memory intensive, etc...,[/color]

Blame the implementation, not the language! :)
[color=blue]
> I find that it complicates the code without being useful. Since it
> is always good to make the readibility of your code better, I would
> really recommend dropping "with" statements and using explicit local
> variable declaration (and duly commented too) instead.[/color]

That is a much better argument. Readable code saves more developer
time than code optimizations save running time :)

/L
--
Lasse Reichstein Nielsen - lrn@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Dr John Stockton
Guest
 
Posts: n/a
#23: Jul 20 '05

re: With clause syntax errors but how do I fix it?


JRS: In article <bj2jv8$aq1$1@news.eusc.inter.net>, seen in
news:comp.lang.javascript, DU <drunclear@hotREMOVEmail.com> posted at
Tue, 2 Sep 2003 13:28:06 :-[color=blue]
>Dr John Stockton wrote:
>[color=green]
>> JRS: In article <bj02q2$bi1$1@news.eusc.inter.net>, seen in
>> news:comp.lang.javascript, DU <drunclear@hotREMOVEmail.com> posted at
>> Mon, 1 Sep 2003 14:23:00 :-
>>[color=darkred]
>>>Finally, please avoid top-posting in this newsgroup.[/color]
>>
>> The term "top-posting" should not be used to a newcomer, since it will
>> not be understood by the average innocent top-poster.
>>[/color]
>
>How do you figure out who is a newcomer in a newsgroup? How can you
>reasonably do that?[/color]

If it is not a newcomer, then it is clearly a person who is not worth
bothering with, or a person who needs a detailed explanation. However,
one can recognise many non-newcomers by name, and many newcomers by what
they write.

[color=blue]
>--[/color]
DSS & STL.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
Closed Thread