I recently started using void for IIFE's with no return value because it's
is by far the clearest way to indicate intent up front and helps to turn
the expression into something of a unique looking construct that helps
clearly identify it. It would be nice to see this practice become more
common because it seems to conveniently solve a number of problems at one.

On Fri, Jun 22, 2012 at 6:23 PM, Jussi Kalliokoski <
jussi.kallioko...@gmail.com> wrote:

> I recently made a blog post concerning this issue [1], and my suggestion
> is to prefix literals (function, array and friends) with `void`, as it's
> almost (if not) designed for this case. So, (function(){}()); becomes void
> function(){}(), [1,2,3].forEach(...) becomes void [1,2,3].forEach(...).
> This is more resistant to typos as well, even in semicolon-preferring code.
>
> Since Claus shared his work on the subject, I thought I'd also share a
> little tool I made [2], called asifier. It's a sort of an education tool
> that could be employed by editors, IDEs and such to show where semicolons
> will be inserted. It can also replace a semicolonless file with inserted
> semicolons so that missing semicolons isn't a problem for projects that
> otherwise follow explicit semicolon rules.
>
> Cheers,
> Jussi
>
> [1] http://blog.avd.io/posts/semicolonoscopy
> [2] https://github.com/jussi-kalliokoski/asifier
>
>
> On Fri, Jun 22, 2012 at 12:08 PM, 程劭非 <csf...@gmail.com> wrote:
>
>> Hi, everyone,
>>
>> During some recent discussion in Chinese JS community, I've noticed
>> several case which JS behave out of user's expect if omitting the
>> semicolon.
>>
>> See the following code:
>> --------------------------------------------
>> var a = this.a  //!!!! here no semicolon will be auto inserted
>> [1,2,3].forEach(function(){
>>    // do something
>> })
>> --------------------------------------------
>> (function(){
>>     //do something
>> })()  //!!!! here no semicolon will be auto inserted
>> (function(){
>>     //do something else
>> })()
>> --------------------------------------------
>>
>> I was thinking that if we could change some grammar rules to make it
>> behave as most user's expect. Just adding several [no LineTerminator
>> here] will do so:
>> --------------------------------------------
>> CallExpression :
>>    MemberExpression [no LineTerminator here] Arguments
>>    CallExpression [no LineTerminator here] Arguments
>>    CallExpression [no LineTerminator here] [ Expression ]
>>    CallExpression . IdentifierName
>> --------------------------------------------
>>
>> Though some of you might consider omitting the semicolon as a bad
>> style, but its used by several group and company (including zepto.js
>> and npmjs).  I think this change will benefit them a lot with very
>> small side effect.
>>
>>
>> /Shaofei
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss@mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to