Reputation: 24587
In JavaScript, one would define a private member variable by making it a local variable in a function that returns a closure:
var count = (function(){
var i = 0;
return function (){ return i++; }
})();
This involves a define-function-then-call-it idiom that is fairly common in JavaScript, but I do not know how it translates in CoffeeScript. Any ideas?
Upvotes: 3
Views: 345
Reputation: 77436
As Brian said, the do
keyword is best. You can also use parens, just as in JavaScript:
count = (->
i = 0
-> i++
)()
Upvotes: 2