Sometimes I write my JS classes like this:
mylib.Container = function() {
var things = [];
// Returns the index of the image added
this.addItem = function(item)
{
things.push(item)
}
}
...
var c = new mylib.Container();
c.addItem(whatever);
I use "constructor-scoped" closured variables (like things
) to avoid this
scoping issues, and I am also using them in tight loops (like the ones used in requestAnimationFrame
). These variables never bleed to the outside of the created fubject.
Is there a way to create and use such variables in CoffeeScript? I know that I have the @ivar
notation which is shorter than this
but something is telling me acessing a closured var
might still be faster...