I have the following CoffeeScript code:
class Person
secret = 0
constructor: (@name, @age, @alive) ->
inc: -> secret++
Which compiles to the following JavaScript code:
var Person;
Person = (function() {
var secret;
secret = 0;
function Person(name, age, alive) {
this.name = name;
this.age = age;
this.alive = alive;
}
Person.prototype.inc = function() {
return secret++;
};
return Person;
})();
Currently secret
is shared between all instances of Person
. Is there a way to make secret
a private instance variable in CoffeeScript?