What is the shortest way of writing the following JavaScript as CoffeeScript?
var obj = {};
(function(){
this.foo = "bar";
}).call(obj);
I can do this:
obj = {}
(->
@foo = "bar"
).call obj
But is there a way to get rid of the parentheses around the function definition? This would almost work:
do =>
@foo = "bar"
…except that the fat arrow operator ‘=>’ automatically binds the function to the current value of ‘this’. Is there a way to specify an alternative ‘this’ value when using the fat arrow?
You can’t get rid of the parentheses, but you can write that function in a single line.