OP's example in coffeescript:
Array::compact = -> x for x in @ when x?
In es6: Array.prototype.compact = function() {
return this.filter(x => x !== null);
}
I find it easier to read than OP's example, but I would like to see non-lexically bound this function shorthand in es6/7. I see a mention of it at the bottom of this spec[1], but not sure what they mean by "Initializer opt". Maybe like this: Array.prototype.compact = this => this.filter(x => x !== null)
[1] http://tc39wiki.calculist.org/es6/arrow-functions/