Skip to content

Instantly share code, notes, and snippets.

@zer09
Forked from isaacs/comma-first-var.js
Created December 28, 2017 05:43
Show Gist options
  • Select an option

  • Save zer09/6b6b0b7f2752e71453afc9dd5633e978 to your computer and use it in GitHub Desktop.

Select an option

Save zer09/6b6b0b7f2752e71453afc9dd5633e978 to your computer and use it in GitHub Desktop.

Revisions

  1. @isaacs isaacs revised this gist Sep 18, 2011. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions comma-first-var.js
    Original file line number Diff line number Diff line change
    @@ -203,7 +203,8 @@ var a = "ape eat banana",

    // Error: Can't call method 'forEach' of undefined.
    // not passing in undefined as an argument!??
    mergeLists([ apple, [ penelope, granger ],
    mergeLists([ apple, [ penelope, granger ] ],
    [ fun ],
    [ 1, 2, 3, 4, 5, 6, 7, 8]
    [ 1, 2, 3, 4, 5, 6, 7, 8 ]
    [ "mary's store has many pies, and cookies, and eggs," ]
    [ function() { doSomething() } ]);
  2. @isaacs isaacs revised this gist Sep 18, 2011. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion comma-first-var.js
    Original file line number Diff line number Diff line change
    @@ -190,6 +190,7 @@ doSomething( aPrettyLongVariableName

    // Addendum 3: More realistic error in standard style:

    // leaks FIVE globals!
    var a = "ape eat banana",
    b = "bat, allowed to fly",
    c = "cat toy",
    @@ -200,7 +201,9 @@ var a = "ape eat banana",
    h = "hat goes on your head",
    i = "ibu isn't a cow";

    // Error: Can't call method 'forEach' of undefined.
    // not passing in undefined as an argument!??
    mergeLists([ apple, [ penelope, granger ],
    [ fun ],
    [ 1, 2, 3, 4, 5, 6, 7, 8]
    [ function() { doSomething() } ]);
    [ function() { doSomething() } ]);
  3. @isaacs isaacs revised this gist Sep 18, 2011. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions comma-first-var.js
    Original file line number Diff line number Diff line change
    @@ -187,3 +187,20 @@ doSomething( aPrettyLongVariableName
    , { a: "is for antelope", b: "is for bat" }
    , 42
    )

    // Addendum 3: More realistic error in standard style:

    var a = "ape eat banana",
    b = "bat, allowed to fly",
    c = "cat toy",
    d = "dog chasing the mailman,"
    e = "elf lord",
    f = "fly through the air",
    g = "gnu is not unix",
    h = "hat goes on your head",
    i = "ibu isn't a cow";

    mergeLists([ apple, [ penelope, granger ],
    [ fun ],
    [ 1, 2, 3, 4, 5, 6, 7, 8]
    [ function() { doSomething() } ]);
  4. isaacs revised this gist May 16, 2010. 1 changed file with 12 additions and 4 deletions.
    16 changes: 12 additions & 4 deletions comma-first-var.js
    Original file line number Diff line number Diff line change
    @@ -167,10 +167,9 @@ return
    // then creates a block with two named statements.

    // this is ok:
    return (
    1
    , 2
    ) // returns 2
    return ( 1
    , 2
    ) // returns 2

    // so is this:
    return (
    @@ -179,3 +178,12 @@ return (
    }
    ) // returns {a:"ape",b:"bat"}


    // Addendum 2: A function call

    doSomething( aPrettyLongVariableName
    , "A string, which has some useful information"
    , "If you put these all together, it'd be too long"
    , { a: "is for antelope", b: "is for bat" }
    , 42
    )
  5. isaacs revised this gist Apr 8, 2010. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions comma-first-var.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,8 @@
    // See comments below.

    // This code sample and justification brought to you by
    // Isaac Z. Schlueter, aka isaacs

    // standard style
    var a = "ape",
    b = "bat",
  6. isaacs revised this gist Apr 8, 2010. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions comma-first-var.js
    Original file line number Diff line number Diff line change
    @@ -144,7 +144,8 @@ return { a : "ape"
    , b : "bat"
    } // returns {a:"ape",b:"bat"}

    // even just separating two values by commas is fine, though a bit silly
    // even just separating two values by commas is fine,
    // though a bit silly
    return 1
    , 2
    , 3
    @@ -159,7 +160,8 @@ return
    return
    { a : "ape"
    , b : "bat"
    } // returns undefined, then creates a block with two named statements.
    } // returns undefined,
    // then creates a block with two named statements.

    // this is ok:
    return (
  7. isaacs revised this gist Apr 8, 2010. 1 changed file with 43 additions and 0 deletions.
    43 changes: 43 additions & 0 deletions comma-first-var.js
    Original file line number Diff line number Diff line change
    @@ -131,3 +131,46 @@ var o =
    [ "gnu", "hat" ]
    , [ "ibu" ]
    ];

    // Addendum: effects on the return statement.
    // It does not break.

    return [ 1
    , 2
    , 3
    ] // returns [1,2,3]

    return { a : "ape"
    , b : "bat"
    } // returns {a:"ape",b:"bat"}

    // even just separating two values by commas is fine, though a bit silly
    return 1
    , 2
    , 3
    , 4 // returns the last value, 4

    // this, however is wrong:
    return
    1
    , 2 // returns undefined, because of semicolon-insertion.

    // so is this. otb == fail.
    return
    { a : "ape"
    , b : "bat"
    } // returns undefined, then creates a block with two named statements.

    // this is ok:
    return (
    1
    , 2
    ) // returns 2

    // so is this:
    return (
    { a : "ape"
    , b : "bat"
    }
    ) // returns {a:"ape",b:"bat"}

  8. isaacs revised this gist Apr 7, 2010. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions comma-first-var.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    // See comments below.

    // standard style
    var a = "ape",
  9. isaacs revised this gist Apr 6, 2010. 1 changed file with 86 additions and 0 deletions.
    86 changes: 86 additions & 0 deletions comma-first-var.js
    Original file line number Diff line number Diff line change
    @@ -44,3 +44,89 @@ var a = "ape"
    , h = "hat"
    , i = "ibu"
    ;

    // Objects:

    // JSON.stringify style
    var o = {
    a : "ape",
    b : "bat",
    c : "cat",
    d : "dog",
    e : "elf",
    f : "fly",
    g : "gnu",
    h : "hat",
    i : "ibu"
    },
    a = [
    [ "ape", "bat" ],
    [ "cat", "dog" ],
    [ "elf", "fly" ],
    [ "gnu", "hat" ],
    [ "ibu" ]
    ];


    // comma-first
    var o =
    { a : "ape"
    , b : "bat"
    , c : "cat"
    , d : "dog"
    , e : "elf"
    , f : "fly"
    , g : "gnu"
    , h : "hat"
    , i : "ibu"
    }
    , a =
    [ [ "ape", "bat" ]
    , [ "cat", "dog" ]
    , [ "elf", "fly" ]
    , [ "gnu", "hat" ]
    , [ "ibu" ]
    ];

    // errors in objects:

    // JSON.stringify style
    var o = {
    a : "ape",
    b : "bat",
    c : "cat",
    d : "dog"
    e : "elf",
    f : "fly",
    g : "gnu",
    h : "hat",
    i : "ibu"
    },
    a = [
    [ "ape", "bat" ],
    [ "cat", "dog" ],
    [ "elf", "fly" ]
    [ "gnu", "hat" ],
    [ "ibu" ]
    ];


    // comma-first
    var o =
    { a : "ape"
    , b : "bat"
    , c : "cat"
    , d : "dog"
    e : "elf"
    , f : "fly"
    , g : "gnu"
    , h : "hat"
    , i : "ibu"
    }
    , a =
    [ [ "ape", "bat" ]
    , [ "cat", "dog" ]
    , [ "elf", "fly" ]
    [ "gnu", "hat" ]
    , [ "ibu" ]
    ];
  10. isaacs created this gist Apr 6, 2010.
    46 changes: 46 additions & 0 deletions comma-first-var.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@

    // standard style
    var a = "ape",
    b = "bat",
    c = "cat",
    d = "dog",
    e = "elf",
    f = "fly",
    g = "gnu",
    h = "hat",
    i = "ibu";

    // comma-first style
    var a = "ape"
    , b = "bat"
    , c = "cat"
    , d = "dog"
    , e = "elf"
    , f = "fly"
    , g = "gnu"
    , h = "hat"
    , i = "ibu"
    ;

    // error in standard style
    var a = "ape",
    b = "bat",
    c = "cat",
    d = "dog"
    e = "elf",
    f = "fly",
    g = "gnu",
    h = "hat",
    i = "ibu";

    // error in comma-first style
    var a = "ape"
    , b = "bat"
    , c = "cat"
    , d = "dog"
    e = "elf"
    , f = "fly"
    , g = "gnu"
    , h = "hat"
    , i = "ibu"
    ;