Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Semantically correct syntax



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

WebmasterWorld Senior Member 5+ Year Member

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)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

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)

WebmasterWorld Senior Member 5+ Year Member

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

Featured Threads

Hot Threads This Week

Hot Threads This Month