Skip to content

Instantly share code, notes, and snippets.

@lumie1337
Last active November 30, 2018 10:34
Show Gist options
  • Save lumie1337/cd90a2839fddb0cc7e894ebad1dedd82 to your computer and use it in GitHub Desktop.
Save lumie1337/cd90a2839fddb0cc7e894ebad1dedd82 to your computer and use it in GitHub Desktop.
conditional rest spread
const oldConcat = Array.prototype.concat;
Array.prototype.concat = function (...args) {
return oldConcat.apply(this, args.map(x => x == null ? [] : x))
}
// now this works
// Note: only works when actually transpiling to [1,2,3].concat(false && [4,5,6])
// does not actually work in chrome console
const some = [
1,
2,
3,
...false && [4,5,6]
]
// some = [1,2,3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment