semi-colon consistency

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
mjanke
Beginner
Beginner
Posts: 9
Joined: Sat Jun 11, 2005 11:52 pm

semi-colon consistency

Post by mjanke »

In this sample line of menu_data.js...

aI("text=some text;url=http://a url goes here;")

Should there be a semi-colon after the closing parenthesis or not? Even the sample menus included are inconsistent in this regard. Some have a semi-colon at the very end after that parenthesis, some don't.

Seems to work either way, but I don't want any surprises.
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

I'm not up on when you 'can' and when you 'must' use a semi-colon in js, however, I would suggest, since the majority of them have semi-colons, that you use them after the closing bracket of an aI string. I do since that is how they all were in the beginning and I know that they work that way in all the browsers I tested. As you said, I have no surprises that way ;)

Ruth
User avatar
Andy
Milonic
Milonic
Posts: 3308
Joined: Sun May 19, 2002 8:23 pm
Location: Menu Developer
Contact:

Post by Andy »

Hi,

With JavaScript the semi-colon is not mandatory, that's why sometimes it's there sometimes not.

However, the semi-colon does indicate end of code line so if you wanted to put your code on one line, you would need to semi-colon.

So this:

Code: Select all

var a=10
var b=123
Is the same as

Code: Select all

var a=10;var b=123
Hope this helps,
Andy
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

Thanks, Andy :D

Ruth
User avatar
Andy
Milonic
Milonic
Posts: 3308
Joined: Sun May 19, 2002 8:23 pm
Location: Menu Developer
Contact:

Post by Andy »

Thanks, Andy
No worries, also note that scripts like Perl and PHP DO need the quotes, otherwise you get a runtime error.

Useful for when you start coding some awesome stuff in PHP. Also, the syntax of PHP is very similar to that of JavaScript - It's all based on the C programming language.

Oh, and somebody asked why variable names have lower case and upper case mixes.

Well, the technical terms for this is camelCase - I use it because it looks a lot neater than camel_case but it's all personal preference.

Here's something about programing in C#:

There's a .net framework recommendation that relates to the accessibility of class members.

1. Identifiers that are public should start with a capital letter. For example, Area starts with A and not a because it's public. This system is known as PascalCase (another programming language) naming scheme.

2. Identifiers that are not public (which include local variables) should start with a lowercase letter. For example, radius starts with r, not R bacause it's private. This is know as camelCase.

It's not that important in JavaScript so everything is in camelCase to make life easier.

Hope I havn't confused you too much,
Andy
Last edited by Andy on Mon Jun 27, 2005 4:15 pm, edited 2 times in total.
User avatar
John
 Team
 Team
Posts: 5967
Joined: Sun May 19, 2002 8:23 pm
Location: Phoenix, AZ
Contact:

Post by John »

Just to add to the mix from the guy lurking out in left field, while not mandatory, as Andy said, we'd really like to see (taking from your example)...

Code: Select all

aI("text=some text;url=http://a url goes here;");
aI("text=some more text;url=http://another url goes here;");
etc.
...simply for consistency.
John
mjanke
Beginner
Beginner
Posts: 9
Joined: Sat Jun 11, 2005 11:52 pm

Post by mjanke »

Thanks, everyone. I'll stick with closing semi-colons on all lines for consistency.
Post Reply