Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:40
semi-colon consistency
Poster: mjanke
Dated: Sunday June 26 2005 - 15:20:18 BST
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.
Poster: Ruth
Dated: Sunday June 26 2005 - 20:05:48 BST
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
Poster: Andy
Dated: Monday June 27 2005 - 11:17:25 BST
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:
var a=10
var b=123
var b=123
Is the same as
Code:
var a=10;var b=123
Hope this helps,
Andy
Poster: Andy
Dated: Monday June 27 2005 - 14:10:11 BST
Quote:
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
Poster: John
Dated: Monday June 27 2005 - 16:07:20 BST
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:
aI("text=some text;url=http://a url goes here;");
aI("text=some more text;url=http://another url goes here;");
etc.
aI("text=some more text;url=http://another url goes here;");
etc.
...simply for consistency.