google-code-export / box2dweb

Automatically exported from code.google.com/p/box2dweb
0 stars 0 forks source link

Semi-colons do not belong at the end of function declarations #24

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
eg.

   function b2BoundValues() {
      b2BoundValues.b2BoundValues.apply(this, arguments);
      if (this.constructor === b2BoundValues) this.b2BoundValues.apply(this, arguments);
   };

They do belong at the end of function expressions, which is correctly reflected 
in the source code

Original issue reported on code.google.com by waldron....@gmail.com on 26 Aug 2011 at 2:02

GoogleCodeExporter commented 9 years ago
Hi,

Is there a good source which confirms your claim?

If I remember correctly, I had some problems with minification when removing 
them, but I'm not sure. Furthermore I read somewhere that they belong there, 
but came to the conclusion that they don't make sense.

Original comment by Uli.He...@googlemail.com on 29 Aug 2011 at 11:17

GoogleCodeExporter commented 9 years ago
http://www.jslint.com/

should hopefully provide an answer.  Minification often requires extra 
semicolons to work flawlessly (because it gets rid of whitespace including 
times where ECMAscript treats a newline differently than a space.  Extra ;'s 
aren't going to hurt anything but if you want syntactical perfection the domain 
above is your definitive guide.

Original comment by breakdan...@gmail.com on 29 Aug 2011 at 4:02

GoogleCodeExporter commented 9 years ago
It's not "[my] claim" - it's the syntactic ASI rules of JavaScript as set forth 
by the ECMAScript spec - dating back to ES1. And yes, JSLint will confirm this, 
eg.

    function foo() {
        return true;
    };            

JSLint Result:

    Problem at line 3 character 2: Unexpected ';'.

As far as minification is concerned, the only expectation is that semi-colons 
are inserted correctly and you'll have no issues. The problem years ago 
centered around concatenating files from varying sources with varying 
reliability.

Original comment by waldron....@gmail.com on 29 Aug 2011 at 4:58

GoogleCodeExporter commented 9 years ago
Yes, JSLint is a perfect source and confirms it. Maybe, "claim" was the wrong 
word to choose ;)

Original comment by Uli.He...@googlemail.com on 29 Aug 2011 at 5:07

GoogleCodeExporter commented 9 years ago
I would recommend a slightly modified function declaration style which is 
correct to add a semi-colon at the end, I believe it is a bit cleaner (and 
shorter than the style you have now):

change:
   function b2Body() {
      ...
   };
   Box2D.Dynamics.b2Body = b2Body;

to:
   Box2D.Dynamics.b2Body = function () {
      ...
   };

Original comment by mpalmer...@gmail.com on 24 Apr 2012 at 3:53

GoogleCodeExporter commented 9 years ago
I'm working on a new version of my compiler at the moment which will not 
produce such a code.

Original comment by Uli.He...@googlemail.com on 24 Apr 2012 at 5:13