I'm using coffeescript to create the following class:
class User
userId: 0
rooms: new Array()
When I create a new instance of the class and add something to the array, any new instance also contains the same array. The generated javascript is:
var User;
User = (function() {
User.name = 'User';
function User() {}
User.prototype.userId = 0;
User.prototype.rooms = new Array();
return User;
})();
How do I design the class that has a new empty array every time I instantiate the class?
User.prototype.room = new Array(), theprototypekeyword here means that all of theUserobjects share this field.