Google Groups

A better underscore for CoffeeScript?


Christer Nilsson Feb 21, 2012 2:00 PM
Posted in group: CoffeeScript
Coffee Comrades!

Underscore is available in both Javascript and Coffeescript versions.
Obviously the CS version is preferable.

The CS version offers two alternative calling models, 1 and 2 below:

0) obj.method(args)
1) _.method(obj,args)
2) _(obj).method(args)

Examples:

0) [1,2,3].include(2)
1) _.include([1,2,3],2)
2) _([1,2,3]).include(2)

Does anyone know if the third modell is available, 0 above?

Yes, I am a purist and allergic to cruft, even if it's only two or three characters.

I see no problem in implementing this, as this can be done quite easy:

Array::include = (item) -> this.indexOf(item) isnt -1

But, there are about sixty more functions and some of them are a lot more complicated.

cheers
Christer