| Semantically correct syntax
|
Readie

msg:4550511 | 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 }
$this.__construct(); } |
| 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?
|
Fotiman

msg:4550514 | 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.
|
Readie

msg:4550555 | 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 :)
|
|
|