homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Semantically correct syntax

 6:36 pm on Mar 2, 2013 (gmt 0)

Hey guys,

I've been wondering about this one for a while. One way I particularly like to structure my code is like this:

systemName.moduleName = new function() {
var $this = this;

$this.__construct = function() {
// Something here

$this.someOtherMethod = function() {
// Something else here


As I feel it makes the code easier to read, allows me to keep it flatter, and I always have access to the this var within the scope of the module (I do a lot of my development in jQuery, so there's often a lot of nested functions).

Anyway, my specific question is whether or not it's semantically correct to include a semi-colon after the closing brace for those function declarations.

From my own perspective, there's an equal argument for and against it.

The argument for: It's a variable declaration
Argument against: It's also a function declaration

Thoughts anyone?



 7:04 pm on Mar 2, 2013 (gmt 0)

Including the semicolon is correct, because ultimately you're doing an assignment operation.
Likewise, there should be a semicolon after the very last closing brace }, because you're doing an assigment to systemName.moduleName.


 11:32 pm on Mar 2, 2013 (gmt 0)

Yea, I guess that makes sense when you think about it like that. Cheers for the input :)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved