Skip to content

Instantly share code, notes, and snippets.

@hhamon
Created March 4, 2012 20:07
Show Gist options
  • Save hhamon/1974593 to your computer and use it in GitHub Desktop.
Save hhamon/1974593 to your computer and use it in GitHub Desktop.
Optional arguments in JS
Reversi.prototype.getNewCell = function (row, col) {
var cell = { 'row': 0, 'col': 0 };
if (undefined !== row) {
cell.row = parseInt(row);
}
if (undefined !== col) {
cell.col = parseInt(col);
}
return cell;
};
@ubermuda
Copy link

ubermuda commented Mar 4, 2012

class Reversi
  getNewCell: (row = 0, col = 0) ->
    { 'row': parseInt(row), 'col': parseInt(col) }

@n1k0
Copy link

n1k0 commented Mar 4, 2012

Reversi::getNewCell = (row, col) -> row: ~~row, col: ~~col

@ubermuda
Copy link

ubermuda commented Mar 4, 2012

how do you get the coloring? :/

also, what is ~~ ?

@ubermuda
Copy link

ubermuda commented Mar 4, 2012

NEVERMIND (bitwise not applied two times)

but the fact that ~undefined == -1 is... disturbing.

@arnaudlimbourg
Copy link

@n1k0 nice but unreadable :)

@n1k0
Copy link

n1k0 commented Mar 4, 2012

@arnaudlimbourg you get used to it :)
@ubermuda comme ça:

```coffeescript
foo = 42
```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment